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

@Entity("developmentRequest")
export class DevelopmentRequest extends EntityBase {
  //PENDING รอดำเนินการ
  //APPROVE อนุมัติ
  //REJECT ไม่อนุมัติ
  @Column({
    nullable: true,
    comment: "สถานะ",
    default: null,
  })
  status: string;

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

  @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: "ชื่อเรื่อง",
    default: null,
  })
  name: string;

  @Column({
    comment: "วิธีพัฒนา70",
    default: false,
  })
  isDevelopment70: boolean;

  @Column({
    comment: "วิธีพัฒนา20",
    default: false,
  })
  isDevelopment20: boolean;

  @Column({
    comment: "วิธีพัฒนา10",
    default: false,
  })
  isDevelopment10: boolean;

  @Column({
    nullable: true,
    comment: "รายละเอียดอื่นๆ 70 แผน",
    default: null,
  })
  reasonDevelopment70: string;

  @Column({
    nullable: true,
    comment: "รายละเอียดอื่นๆ 20 แผน",
    default: null,
  })
  reasonDevelopment20: string;

  @Column({
    nullable: true,
    comment: "รายละเอียดอื่นๆ 10 แผน",
    default: null,
  })
  reasonDevelopment10: string;

  @Column({
    nullable: true,
    comment: "เป้าหมายการนำไปพัฒนางาน",
    length: 255,
    default: null,
  })
  developmentTarget: string;

  @Column({
    nullable: true,
    comment: "วิธีการวัดผลการพัฒนา",
    length: 255,
    default: null,
  })
  developmentResults: string;

  @Column({
    nullable: true,
    comment: "รายงานผลการพัฒนา",
    length: 255,
    default: null,
  })
  developmentReport: string;

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

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

  @OneToMany(
    () => DevelopmentProject,
    (developmentProject) => developmentProject.developmentRequest,
  )
  developmentProjects: DevelopmentProject[];
}

export class CreateDevelopmentRequest {
  name: string | null;
  developmentTarget: string | null;
  developmentResults: string | null;
  developmentReport: string | null;
  reasonDevelopment70?: string | null;
  reasonDevelopment20?: string | null;
  reasonDevelopment10?: string | null;
  isDevelopment70: boolean | null;
  isDevelopment20: boolean | null;
  isDevelopment10: boolean | null;
  developmentProjects?: string[];
}
