import { Column, Entity, ManyToOne, PrimaryGeneratedColumn, Unique } from "typeorm";
import { InspectionPointEnum } from "../../../enums/inspectionEnum";
import { inspectionVersionedPlan } from "./inspectionVersionedPlan";

@Entity()
export class inspectionPoint {
  @PrimaryGeneratedColumn("uuid")
  id: string;

  @Column({ type: "varchar", length: 255 })
  title: string;

  @Column({ type: "text" })
  description: string;

  @Column({
    type: "varchar",
    length: 255,
    transformer: {
      to(value: InspectionPointEnum) {
        return value.toString();
      },
      from(value: string) {
        return InspectionPointEnum[value as keyof typeof InspectionPointEnum];
      },
    },
  })
  type: InspectionPointEnum;

  @Column({ type: "int", nullable: true, default: null })
  min: number;

  @Column({ type: "int", nullable: true, default: null })
  max: number;

  @Column({ type: "int", default: 0 })
  sort: number;

  @Column()
  versionedPlanId: string;

  @ManyToOne(() => inspectionVersionedPlan, {
    nullable: false,
    onDelete: "CASCADE",
    onUpdate: "RESTRICT",
  })
  versionedPlan: inspectionVersionedPlan;
}