import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { MetaStateOperator } from "./MetaStateOperator";
import { MetaWorkflow } from "./MetaWorkflow";

@Entity("metaState")
export class MetaState 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)ของตาราง metaWorkflow",
    default: null,
  })
  metaWorkflowId: string;

  @ManyToOne(() => MetaWorkflow, (metaWorkflow) => metaWorkflow.metaStates)
  @JoinColumn({ name: "metaWorkflowId" })
  metaWorkflow: MetaWorkflow;

  @OneToMany(() => MetaStateOperator, (metaStateOperator) => metaStateOperator.metaState)
  metaStateOperators: MetaStateOperator[];
}
