import {
  IsOptional,
  IsString,
  IsNumber,
  ValidateNested,
  IsEnum,
} from 'class-validator';
import { Type } from 'class-transformer';
import { ApiProperty } from '@nestjs/swagger';

export enum SortDirection {
  ASC = 'asc',
  DESC = 'desc',
}

export class SortParams {
  @ApiProperty({ required: false, enum: SortDirection })
  @IsOptional()
  @IsEnum(SortDirection)
  direction?: SortDirection;

  @ApiProperty({ required: false })
  @IsOptional()
  @IsString()
  field?: string;
}

export class PriceFilter {
  @ApiProperty({ required: false })
  @IsOptional()
  @IsNumber()
  minvalue?: number;

  @ApiProperty({ required: false })
  @IsOptional()
  @IsNumber()
  maxvalue?: number;
}

export class FilterParams {
  @ApiProperty({ required: false, type: PriceFilter })
  @IsOptional()
  @ValidateNested()
  @Type(() => PriceFilter)
  price?: PriceFilter;
}

export class CatalogParamsDto {
  @ApiProperty({ required: false })
  @IsOptional()
  @IsString()
  search?: string;

  @ApiProperty({ required: false, type: SortParams })
  @IsOptional()
  @ValidateNested()
  @Type(() => SortParams)
  sort?: SortParams;

  @ApiProperty({ required: false, type: FilterParams })
  @IsOptional()
  @ValidateNested()
  @Type(() => FilterParams)
  filter?: FilterParams;
}
