import {
  Entity,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  PrimaryColumn,
  OneToMany,
} from "typeorm";
import { CommandType } from "./CommandType";
import { CommandSalary } from "./CommandSalary";
import { Assign } from "./Assign";

@Entity("commandSys")
export class CommandSys {
  @PrimaryColumn({
    comment: "ไอดีหลักของตาราง",
    length: 255,
  })
  id: string;

  @CreateDateColumn({ comment: "สร้างข้อมูลเมื่อ" })
  createdAt!: Date;

  @Column({
    comment: "User Id ที่สร้างข้อมูล",
    length: 40,
    default: "00000000-0000-0000-0000-000000000000",
  })
  createdUserId!: String;

  @UpdateDateColumn({ comment: "แก้ไขข้อมูลล่าสุดเมื่อ" })
  lastUpdatedAt!: Date;

  @Column({
    comment: "User Id ที่แก้ไขข้อมูล",
    length: 40,
    default: "00000000-0000-0000-0000-000000000000",
  })
  lastUpdateUserId!: String;

  @Column({ comment: "ชื่อ User ที่สร้างข้อมูล", length: 200, default: "string" })
  createdFullName!: String;

  @Column({ comment: "ชื่อ User ที่แก้ไขข้อมูลล่าสุด", length: 200, default: "string" })
  lastUpdateFullName!: String;

  @Column({
    nullable: true,
    comment: "ชื่อระบบ",
    length: 255,
    default: null,
  })
  sysName: string;

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

  @Column({
    nullable: true,
    comment: "ลำดับแสดงผล",
    default: null,
  })
  order: number;

  @OneToMany(() => CommandType, (commandType) => commandType.commandTypeSys)
  commandTypes: CommandType[];

  @OneToMany(() => CommandSalary, (commandSalary) => commandSalary.commandSalarySys)
  commandSalarys: CommandSalary[];

  @OneToMany(() => Assign, (assgin) => assgin.commandAssignSys)
  assgins: Assign[];

  //   @OneToMany(() => Workflow, (workflow) => workflow.commandSys)
  //   workflows: Workflow[];
}

export class CreateCommandSys {
  @PrimaryColumn()
  id: string;

  @Column()
  sysName: string;

  @Column()
  sysDescription: string;
}

export class UpdateCommandSys {
  @Column()
  sysName: string;

  @Column()
  sysDescription: string;
}
