import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { StateOperator } from "./StateOperator";
import { Workflow } from "./Workflow";
import { StateUserComment } from "./StateUserComment";

@Entity("state")
export class State extends EntityBase {
  @Column({
    nullable: true,
    comment: "ชื่อประเภทขั้นตอน",
    length: 255,
    default: null,
  })
  name: string;

  @Column({
    nullable: true,
    comment: "ประเภทขั้นตอน",
    length: 255,
    default: null,
  })
  type: string;

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

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

  @ManyToOne(() => Workflow, (workflow) => workflow.states)
  @JoinColumn({ name: "workflowId" })
  workflow: Workflow;

  @OneToMany(() => StateOperator, (stateOperator) => stateOperator.state)
  stateOperators: StateOperator[];

  @OneToMany(() => StateUserComment, (stateUserComment) => stateUserComment.state)
  stateUserComments: StateUserComment[];
}
