import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
import { EntityBase } from "./base/Base";
import { ProfileCertificate } from "./ProfileCertificate";

@Entity("profileCertificateHistory")
export class ProfileCertificateHistory extends EntityBase {
  @Column({
    nullable: true,
    type: "datetime",
    comment: "วันที่หมดอายุ",
    default: null,
  })
  expireDate: Date;

  @Column({
    nullable: true,
    type: "datetime",
    comment: "วันที่ออกใบอนุญาต",
    default: null,
  })
  issueDate: Date;

  @Column({
    nullable: true,
    comment: "เลขที่ใบอนุญาต",
    length: 20,
    default: null,
  })
  certificateNo: string;

  @Column({
    nullable: true,
    comment: "ชื่อใบอนุญาต",
    length: 100,
    default: null,
  })
  certificateType: string;

  @Column({
    nullable: true,
    comment: "หน่วยงานผู้ออกใบอนุญาต",
    length: 200,
    default: null,
  })
  issuer: string;

  @Column({
    comment: "แนบไฟล์เอกสาร",
    default: false,
  })
  isUpload: boolean;

  @Column({
    nullable: true,
    length: 40,
    comment: "คีย์นอก(FK)ของตาราง ProfileCertificate",
    default: null,
  })
  profileCertificateId: string;

  @Column({
    nullable: false,
    comment: "สถานะลบข้อมูล",
    default: false,
  })
  isDeleted: boolean;

  @ManyToOne(
    () => ProfileCertificate,
    (profileCertificate) => profileCertificate.profileCertificateHistories,
  )
  @JoinColumn({ name: "profileCertificateId" })
  histories: ProfileCertificate;
}

export class CreateProfileCertificateHistory {
  @Column()
  expireDate: Date | null;

  @Column()
  issueDate: Date | null;

  @Column()
  certificateNo: string | null;

  @Column()
  certificateType: string | null;

  @Column()
  issuer: string | null;

  @Column("uuid")
  profileCertificateId: string | null;
}

export type UpdateProfileCertificateHistory = Partial<CreateProfileCertificateHistory>;
