import {
    Column,
    CreateDateColumn,
    Entity,
    Index,
    ManyToOne,
    OneToMany,
    PrimaryGeneratedColumn,
    UpdateDateColumn,
  } from 'typeorm';
  import { Office } from './office.entity';
  import { UserRole } from './user-role.entity';

  @Entity({ name: 'users' })
  export class User {
    @PrimaryGeneratedColumn('uuid')
    id!: string;

    @Index({ unique: true })
    @Column({ type: 'varchar', length: 200 })
    email!: string;

    @Column({ type: 'varchar', length: 100, nullable: true })
    username?: string;

    @Column({ type: 'varchar', length: 200 })
    fullName!: string;

    @Column({ type: 'varchar', length: 50, nullable: true })
    phone?: string;

    @Column({ type: 'varchar', length: 255 })
    passwordHash!: string;

    @Column({ default: true })
    active!: boolean;

    @Column({ default: false })
    isBypass!: boolean;

    @Column({ type: 'varchar', name: 'office_id', nullable: true })
    officeId?: string;

    @ManyToOne(() => Office, { nullable: true, onDelete: 'SET NULL' })
    office?: Office;

    @OneToMany(() => UserRole, (ur) => ur.user)
    userRoles!: UserRole[];

    @Column({ type: 'datetime', nullable: true })
    lastLoginAt?: Date;

    @CreateDateColumn()
    createdAt!: Date;

    @UpdateDateColumn()
    updatedAt!: Date;
  }
  