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

import { CreateDropdownOptionDto } from "./create-dropdown-option.dto";
import { DropdownSettingMetaDto } from "./dropdown-setting-meta.dto";

export class CreateDropdownSettingDto {
  @IsString()
  @MaxLength(128)
  @Matches(/^[a-z][a-z0-9_]*$/i, {
    message: "code must be snake_case-friendly (letters, digits, underscores)",
  })
  code!: string;

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

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

  @IsOptional()
  @IsBoolean()
  multiple?: boolean;

  @IsOptional()
  @ValidateNested()
  @Type(() => DropdownSettingMetaDto)
  meta?: DropdownSettingMetaDto;

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