import { Entity, Column, JoinColumn, ManyToOne, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { CommandType } from "./CommandType";
import { CommandSend } from "./CommandSend";
import { CommandSalary } from "./CommandSalary";
import { CommandRecive } from "./CommandRecive";
import { CommandOperator } from "./CommandOperator";
import { ProfileSalary } from "./ProfileSalary";
import { ProfileSalaryHistory } from "./ProfileSalaryHistory";
import { CommandSign } from "./CommandSign";
import { ProfileSalaryTemp } from "./ProfileSalaryTemp";

@Entity("command")
export class Command extends EntityBase {
  // NEW = ใหม่
  // DRAFT = แบบร่าง
  // PENDING = รอผู้มีอำนาจ
  // WAITING = รอออกคำสั่ง
  // REPORTED = ออกคำสั่งเสร็จสิ้น
  // CANCEL = ยกเลิก
  @Column({
    nullable: true,
    comment: "สถานะ",
    length: 20,
    default: null,
  })
  status: string;

  @Column({
    nullable: true,
    comment: "คำสั่งเรื่อง",
    length: 255,
    default: null,
  })
  issue: string;

  @Column({
    nullable: true,
    comment: "ชื่อย่อหน่วยงานที่ออกคำสั่ง",
    length: 16,
    default: null,
  })
  shortName: string;

  @Column({
    nullable: true,
    comment: "เลขที่คำสั่ง",
    length: 255,
    default: null,
  })
  commandNo: string;

  @Column({
    nullable: true,
    comment: "ปี",
    default: null,
  })
  commandYear: number;

  @Column({
    nullable: true,
    type: "datetime",
    comment: "วันที่ลงนาม",
    default: null,
  })
  commandAffectDate: Date;

  @Column({
    nullable: true,
    type: "datetime",
    comment: "วันที่คำสั่งมีผล",
    default: null,
  })
  commandExcecuteDate: Date;

  @Column({
    nullable: true,
    comment: "เนื้อหาคำสั่งส่วนต้น",
    type: "text",
    default: null,
  })
  detailHeader: string;

  @Column({
    nullable: true,
    comment: "เนื้อหาคำสั่งส่วนกลาง",
    type: "text",
    default: null,
  })
  detailBody: string;

  @Column({
    nullable: true,
    comment: "เนื้อหาคำสั่งส่วนท้าย",
    type: "text",
    default: null,
  })
  detailFooter: string;

  @Column({
    nullable: true,
    comment: "ตำแหน่ง",
    type: "text",
    default: null,
  })
  positionDetail: string;

  @Column({
    nullable: true,
    comment: "คำสั่งกรุงเทพมหานคร",
    length: 20,
    default: null,
  })
  isBangkok: string;

  @Column({
    comment: "สถานะบัญชีแนบท้าย",
    default: true,
  })
  isAttachment: boolean;

  @Column({
    comment: "อัปโหลดบัญชีแนบท้าย",
    default: true,
  })
  isUploadAttachment: boolean;

  @Column({
    comment: "ออกคำสั่งแบบ Digital Signature",
    default: null,
  })
  isSignature: boolean;

  @Column({
    comment: "ยืนยันทำแบบร่าง",
    default: false,
  })
  isDraft: boolean;

  @Column({
    comment: "ผู้มีอำนาจลงนาม",
    default: false,
  })
  isSign: boolean;

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

  @ManyToOne(() => CommandType, (commandType) => commandType.commands)
  @JoinColumn({ name: "commandTypeId" })
  commandType: CommandType;

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

  @ManyToOne(() => CommandSalary, (commandSalary) => commandSalary.commands)
  @JoinColumn({ name: "commandSalaryId" })
  commandSalary: CommandSalary;

  @OneToMany(() => CommandSend, (commandSend) => commandSend.command)
  commandSends: CommandSend[];

  @OneToMany(() => CommandSign, (commandSign) => commandSign.command)
  commandSigns: CommandSign[];

  @OneToMany(() => CommandRecive, (commandRecive) => commandRecive.command)
  commandRecives: CommandRecive[];

  @OneToMany(() => CommandOperator, (commandOperator) => commandOperator.command)
  commandOperators: CommandOperator[];

  @OneToMany(() => ProfileSalary, (profileSalary) => profileSalary.command)
  profileSalarys: ProfileSalary[];

  @OneToMany(() => ProfileSalaryTemp, (profileSalaryTemp) => profileSalaryTemp.command)
  profileSalaryTemps: ProfileSalaryTemp[];

  @OneToMany(() => ProfileSalaryHistory, (profileSalaryHistory) => profileSalaryHistory.command)
  profileSalaryHistorys: ProfileSalaryHistory[];
}

export class CreateCommand {
  @Column()
  name: string;
}

// export type UpdateCommand = Partial<CreateCommand>;
