import {
  BaseEntity,
  BeforeInsert,
  BeforeUpdate,
  Column,
  CreateDateColumn,
  Entity,
  PrimaryGeneratedColumn,
} from 'typeorm';
import * as bycrypt from 'bcrypt';

@Entity('user')
export class User extends BaseEntity {
  @PrimaryGeneratedColumn({
    comment: 'the unique identifier',
  })
  idUser: number;

  @Column({
    type: 'varchar',
    length: 255,
    nullable: false,
  })
  Full_Name: string;

  @Column({
    type: 'varchar',
    length: 255,
    nullable: false,
    unique: true,
  })
  Email: string;

  @Column({
    type: 'varchar',
    length: 255,
    nullable: false,
  })
  Password: string;

  @Column({
    type: 'varchar',
    length: 255,
    nullable: true,
  })
  OTP: string;

  @Column({
    type: 'varchar',
    length: 255,
    nullable: true,
  })
  OTP_Time: string;

  @Column({
    type: 'varchar',
    length: 255,
    nullable: true,
    default: '1',
  })
  Status: string;
  @Column({
    type: 'varchar',
    length: 255,
    nullable: true,
    default: '1',
  })
  Previlage_Status: string;

  @CreateDateColumn()
  CreatedAt: Date;

  // @BeforeInsert()
  // async hasPass() {
  //   const salt = await bycrypt.genSalt();
  //   this.Password = await bycrypt.hash(this.Password, salt);
  // }

  // @BeforeUpdate()
  // async hasPasswhenUpdating() {
  //   const salt = await bycrypt.genSalt();
  //   this.Password = await bycrypt.hash(this.Password, salt);
  // }
}
