import { Entity, Column, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { OrgRoot } from "./OrgRoot";
import { PosMaster } from "./PosMaster";
import { OrgChild1 } from "./OrgChild1";
import { OrgChild2 } from "./OrgChild2";
import { OrgChild3 } from "./OrgChild3";
import { OrgChild4 } from "./OrgChild4";
import { EmployeePosMaster } from "./EmployeePosMaster";
import { EmployeeTempPosMaster } from "./EmployeeTempPosMaster";

@Entity("orgRevision")
export class OrgRevision extends EntityBase {
  @Column({
    comment: "ชื่อของโครงสร้าง",
    length: 255,
    default: null,
  })
  orgRevisionName: string;

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

  @Column({
    comment: "สถานะเป็นโครงสร้างปัจจุบันหรือไม่",
    default: false,
  })
  orgRevisionIsCurrent: boolean;

  @Column({
    nullable: true,
    type: "datetime",
    comment: "วันเวลาที่สร้างโครงสร้าง",
    default: null,
  })
  orgRevisionCreatedAt: Date;

  @Column({
    nullable: true,
    type: "datetime",
    comment: "เวลาเผยแพร่",
    default: null,
  })
  orgPublishDate: Date;

  @Column({
    comment: "สถานะเป็นโครงสร้างแบบร่างหรือไม่",
    default: false,
  })
  orgRevisionIsDraft: boolean;

  @Column({
    comment: "สถานะเช็คโครงสร้างส่งคนไปออกคำสั่งหรือไม่",
    default: false,
  })
  isLock: boolean;

  @OneToMany(() => PosMaster, (posMaster) => posMaster.orgRevision)
  posMasters: PosMaster[];

  @OneToMany(() => EmployeePosMaster, (employeePosMaster) => employeePosMaster.orgRevision)
  employeePosMasters: EmployeePosMaster[];

  @OneToMany(
    () => EmployeeTempPosMaster,
    (employeeTempPosMaster) => employeeTempPosMaster.orgRevision,
  )
  employeeTempPosMasters: EmployeeTempPosMaster[];

  @OneToMany(() => OrgRoot, (orgRoot) => orgRoot.orgRevision)
  orgRoots: OrgRoot[];

  @OneToMany(() => OrgChild1, (orgChild1) => orgChild1.orgRevision)
  orgChild1s: OrgChild1[];

  @OneToMany(() => OrgChild2, (orgChild2) => orgChild2.orgRevision)
  orgChild2s: OrgChild2[];

  @OneToMany(() => OrgChild3, (orgChild3) => orgChild3.orgRevision)
  orgChild3s: OrgChild3[];

  @OneToMany(() => OrgChild4, (orgChild4) => orgChild4.orgRevision)
  orgChild4s: OrgChild4[];
}

export class CreateOrgRevision {
  @Column()
  orgRevisionName: string;

  @Column()
  typeDraft: string;

  @Column("uuid")
  orgRevisionId?: string;

  @Column()
  remark: string;
}
export type UpdateOrgRevision = Partial<OrgRevision>;
