import {
  AllowNull,
  BelongsTo,
  Column,
  DataType,
  ForeignKey,
  Table,
} from "sequelize-typescript";
import { TimestampModel } from "src/database/models/timestamp.model";
import { User } from "./user.model";
import { ACTIVE, CANCELLED, DEACTIVATE, EXPIRED } from "src/common/constant";

@Table({ timestamps: true, tableName: "password_resets" })
export class PasswordReset extends TimestampModel {
  @ForeignKey(() => User)
  @Column({ field: "user_id" })
  userId: number;

  @AllowNull(true)
  @Column({ field: "phone_number" })
  phoneNumber: string;

  @AllowNull(true)
  @Column
  email: string;

  @AllowNull(false)
  @Column
  token: string;

  @AllowNull(false)
  @Column({ field: 'expired_at' })
  expiredAt: Date;

  @AllowNull(false)
  @Column({
    type: DataType.ENUM(
      ACTIVE,
      DEACTIVATE,
      CANCELLED,
      EXPIRED
    )
  })
  status: string;

  @BelongsTo(() => User)
  user: User;
}
