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

@Entity("profileEdit")
export class ProfileEdit extends EntityBase {
  @Column({
    nullable: true,
    length: 40,
    comment: "คีย์นอก(FK)ของตาราง Profile",
    default: null,
  })
  profileId: string;

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

  @Column({
    nullable: true,
    comment: "สถานะคำร้อง", //PENDING = รอดำเนินการ, COMPLETE = ดำเนินการแก้ไขแล้ว, REJECT = ไม่อนุมัตการแก้ไข
    default: null,
  })
  status: string;

  @Column({
    nullable: true,
    comment: "ชื่อเรื่อง",
    default: null,
  })
  topic: string;

  @Column({
    nullable: true,
    comment: "รายละเอียด",
    type: "text",
    default: null,
  })
  detail: string;

  @Column({
    nullable: true,
    comment: "หมายเหตุ",
    type: "text",
    default: null,
  })
  remark: string;

  @ManyToOne(() => Profile, (profile) => profile.profileEdits)
  @JoinColumn({ name: "profileId" })
  profile: Profile;

  @ManyToOne(() => ProfileEmployee, (ProfileEmployee) => ProfileEmployee.profileEdits)
  @JoinColumn({ name: "profileEmployeeId" })
  profileEmployee: ProfileEmployee;
}

export class CreateProfileEdit {
  profileId: string;
  topic: string | null;
  detail: string | null;
}

export class EditProfileEdit {
  topic?: string | null;
  detail?: string | null;
  remark?: string | null;
  status?: string | null;
}

export class CreateProfileEmployeeEdit {
  profileEmployeeId: string;
  topic: string | null;
  detail: string | null;
}

export class EditProfileEmployeeEdit {
  topic?: string | null;
  detail?: string | null;
  remark?: string | null;
  status?: string | null;
}

export type UpdateProfileEdit = {
  detail?: string | null;
  date?: Date | null;
};
