import { Type } from 'class-transformer';
import {
  ArrayNotEmpty,
  IsArray,
  IsByteLength,
  IsInt,
  IsNotEmpty,
  IsString,
  MaxLength,
  Min,
  ValidateNested,
} from 'class-validator';
import { TransformNumberArray } from '../../../shared/decorators/class-transformer/transform-number-array.decorator';
import { TransformNumber } from '../../../shared/decorators/class-transformer/transform-number.decorator';
import { CreateFoodDto } from '../../../shared/dtos/foods/create-food.dto';
import { IsOptional } from '../../../shared/decorators/class-validator/is-optional.decorator';
import { MatchesNamesRegex } from '../../../shared/decorators/class-validator/matches-names-regex.decorator';

export class CreateRecipeDto {
  @IsString()
  @IsNotEmpty()
  @MaxLength(50)
  @MatchesNamesRegex()
  name: string;

  @TransformNumber()
  @IsInt()
  @Min(1)
  servings: number;

  @IsArray()
  @ArrayNotEmpty()
  @ValidateNested({ each: true })
  @Type(() => CreateFoodDto)
  ingredients: CreateFoodDto[];

  @IsArray()
  @ArrayNotEmpty()
  @IsString({ each: true })
  @IsByteLength(1, 65536, { each: true })
  stepBySteps: string[];

  @IsOptional()
  @TransformNumberArray()
  @IsArray()
  @IsInt({ each: true })
  @Min(1, { each: true })
  tagsIds?: number[];
}
