import { Type } from "class-transformer";
import {
  IsArray,
  IsEnum,
  IsOptional,
  IsString,
  MaxLength,
  ValidateNested,
} from "class-validator";

import { CreateFileUploadFieldDto } from "./create-file-upload-field.dto";

export enum FileUploadEntityDto {
  Customer = "customer",
  Booking = "booking",
  Consignment = "consignment",
  Shipment = "shipment",
  Invoice = "invoice",
  Train = "train",
  Other = "other",
}

export class CreateFileUploadSettingDto {
  @IsString()
  @MaxLength(128)
  code!: string;

  @IsString()
  @MaxLength(256)
  label!: string;

  @IsOptional()
  @IsString()
  description?: string;

  @IsEnum(FileUploadEntityDto)
  entity!: FileUploadEntityDto;

  @IsOptional()
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => CreateFileUploadFieldDto)
  fields?: CreateFileUploadFieldDto[];
}
