import { Type } from 'class-transformer';
import {
  ArrayMaxSize,
  IsArray,
  IsDate,
  IsInt,
  Min,
  ValidateNested,
} from 'class-validator';
import { TransformDate } from '../../../../../shared/decorators/class-transformer/transform-date.decorator';
import { TransformNumber } from '../../../../../shared/decorators/class-transformer/transform-number.decorator';
import { MinDate } from '../../../../../shared/decorators/class-validator/min-date.decorator';
import { CreateFoodDto } from '../../../../../shared/dtos/foods/create-food.dto';
import { IsOptional } from '../../../../../shared/decorators/class-validator/is-optional.decorator';

export class CreateMeal_Recipe {
  @TransformNumber()
  @IsInt()
  @Min(1)
  id: number;

  @TransformNumber()
  @IsInt()
  @Min(1)
  consumedServings: number;
}

export class CreateMealDto {
  @TransformDate()
  @IsDate()
  @MinDate('1900-01-01')
  date: Date;

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

  @IsOptional()
  @IsArray()
  @ArrayMaxSize(48)
  @ValidateNested({ each: true })
  @Type(() => CreateFoodDto)
  foods?: CreateFoodDto[];

  @IsOptional()
  @IsArray()
  @ArrayMaxSize(16)
  @ValidateNested({ each: true })
  @Type(() => CreateMeal_Recipe)
  recipes?: CreateMeal_Recipe[];
}
