import { PredictionCardType, PredictionValueType } from '@prisma/client';
import { Type } from 'class-transformer';
import {
  IsArray,
  IsEnum,
  IsInt,
  IsOptional,
  IsString,
  MaxLength,
  Min,
  ValidateNested,
} from 'class-validator';
import { CardFieldDto } from './card-field.dto';
import { CardOptionDto } from './card-option.dto';

export class CreateCardDto {
  @IsString()
  @MaxLength(120)
  title!: string;

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

  @IsEnum(PredictionCardType)
  type!: PredictionCardType;

  @IsEnum(PredictionValueType)
  valueType!: PredictionValueType;

  @IsOptional()
  @IsInt()
  styleId?: number;

  @IsOptional()
  @IsString()
  @MaxLength(20)
  unit?: string;

  @IsOptional()
  @IsInt()
  @Min(0)
  sortOrder?: number;

  @IsOptional()
  @IsInt()
  @Min(0)
  basePoints?: number;

  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => CardFieldDto)
  fields!: CardFieldDto[];

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