import { BaseEntity } from "@edr/api-common";
import {
  Column,
  Entity,
  Index,
  OneToMany,
} from "typeorm";

import { FileUploadField } from "./file-upload-field.entity";

@Entity({ schema:"freight",name: "file_upload_settings" })
@Index(["code"], { unique: true })
export class FileUploadSetting extends BaseEntity {
  @Column({
    name: "code",
    type: "varchar",
    length: 128,
    unique: true,
  })
  code!: string;

  @Column({
    name: "label",
    type: "varchar",
    length: 256,
  })
  label!: string;

  @Column({
    name: "description",
    type: "text",
    nullable: true,
  })
  description?: string | null;

  @Column({
    name: "entity",
    type: "varchar",
    length: 32,
    default: "other",
  })
  entity!: string;

  @OneToMany(
    () => FileUploadField,
    (field) => field.setting,
    {
      cascade: true,
    }
  )
  fields!: FileUploadField[];
}