import { Transform } from 'class-transformer';
import {
  ArrayMaxSize,
  ArrayNotEmpty,
  ArrayUnique,
  IsArray,
  IsInt,
  IsNotEmpty,
  IsString,
  Matches,
  MaxLength,
  Min,
  ValidateIf,
} 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 { IsOptional } from '../../../../../shared/decorators/class-validator/is-optional.decorator';
import { MatchesNamesRegex } from '../../../../../shared/decorators/class-validator/matches-names-regex.decorator';

export class RetrieveMealsTimesQueryParamsDto {
  @ValidateIf((object: RetrieveMealsTimesQueryParamsDto) => !object.ids)
  @Transform(({ obj, value }) => (!obj.ids ? value : undefined))
  @TransformNumber()
  @IsInt()
  @Min(1)
  page?: number = 1;

  @ValidateIf((object: RetrieveMealsTimesQueryParamsDto) => !object.ids)
  @Transform(({ obj, value }) => (!obj.ids ? value : undefined))
  @IsOptional()
  @IsString()
  @IsNotEmpty()
  @MaxLength(30)
  @MatchesNamesRegex()
  search_by_name?: string;

  @IsOptional()
  @TransformNumberArray()
  @IsArray()
  @ArrayUnique()
  @ArrayNotEmpty()
  @ArrayMaxSize(20)
  @IsInt({ each: true })
  @Min(1, { each: true })
  ids?: number[];
}

export class RetrieveMealsTimes_MealTime {
  id: number;
  name: string;
}

export class RetrieveMealsTimesResponseDto {
  data: RetrieveMealsTimes_MealTime[];
  actualPage?: number;
  totalPages?: number;
}
