import { AdminResetCode } from 'src/auth/admin/entitites/admin-reset-code.entity';
import { ADMIN_ROLE } from 'src/shared/enum/admin-role.enum';
import { UserStatus } from 'src/shared/enum/user-status.enum';
import { Town } from 'src/town/entities/town.entity';
import { Entity, Column, PrimaryColumn, JoinColumn, ManyToOne, OneToMany } from 'typeorm';

@Entity()
export class Admin {
  @PrimaryColumn()
  email: string;

  @JoinColumn({ name: 'idTown' })
  @ManyToOne(() => Town, (town) => town.townId, { nullable: true, eager: true })
  idTown: Town;

  @Column()
  name: string;

  @Column()
  lastName: string;

  @Column({
    type: 'enum',
    enum: ADMIN_ROLE,
    default: ADMIN_ROLE.ADMIN,
  })
  role: string;

  @Column()
  password: string;

  @Column({
    type: 'enum',
    enum: UserStatus,
    default: 'active',
  })
  status: UserStatus = UserStatus.ACTIVE;

  @OneToMany(() => AdminResetCode, (resetCode) => resetCode.admin)
  resetCodes: AdminResetCode[];
}
