import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { EmployeePosDict } from "./EmployeePosDict";
import { EmployeePosType } from "./EmployeePosType";
import { EmployeePosition } from "./EmployeePosition";
import { ProfileEmployee } from "./ProfileEmployee";

enum EmployeePosLevelAuthoritys {
  HEAD = "HEAD",
  DEPUTY = "DEPUTY",
  GOVERNOR = "GOVERNOR",
}
@Entity("employeePosLevel")
export class EmployeePosLevel extends EntityBase {
  @Column({
    comment: "ชื่อระดับชั้นงาน",
    // type: "int",
    nullable: true,
    length: 255,
    default: null,
  })
  // posLevelName: number;
  posLevelName: string;

  @Column({
    comment: "ระดับของระดับชั้นงาน",
    type: "int",
  })
  posLevelRank: number;

  @Column({
    nullable: true,
    comment:
      "ผู้มีอำนาจสั่งบรรจุของระดับนี้ head = หัวหน้าหน่วยงาน , deputy = ปลัด , governor = ผู้ว่าฯ",
    type: "enum",
    enum: EmployeePosLevelAuthoritys,
    default: null,
  })
  posLevelAuthority: EmployeePosLevelAuthoritys;

  @Column({
    length: 40,
    comment: "คีย์นอก(FK)ของตาราง employeePosType",
  })
  posTypeId: string;

  @ManyToOne(() => EmployeePosType, (posType) => posType.posLevels)
  @JoinColumn({ name: "posTypeId" })
  posType: EmployeePosType;

  @OneToMany(() => EmployeePosition, (position) => position.posLevel)
  positions: EmployeePosition[];

  @OneToMany(() => EmployeePosDict, (posDict) => posDict.posLevel)
  posDicts: EmployeePosDict[];

  @OneToMany(() => ProfileEmployee, (profile) => profile.posLevel)
  profiles: ProfileEmployee[];

  @OneToMany(() => ProfileEmployee, (profile) => profile.posLevelTemp)
  profilesTemp: ProfileEmployee[];
}

export class CreateEmployeePosLevel {
  @Column()
  posLevelName: string;

  @Column()
  posLevelRank: number;

  @Column()
  posLevelAuthority: string;

  @Column("uuid")
  posTypeId: string;
}

export type UpdateEmployeePosLevel = Partial<CreateEmployeePosLevel> & {
  posLevelAuthority: EmployeePosLevelAuthoritys;
};
