import { ApiProperty } from "@nestjs/swagger";
import { Transform } from "class-transformer";
import { IsNumber, IsOptional, IsString } from "class-validator";
import { toNumber } from "src/common/cast";

export class QueryDto {
  @ApiProperty({ 
    example: 1, 
    required: false, 
    default: 1,
    description: "Page number"
  })
  @Transform(({ value }) => toNumber(value, { default: 1, min: 1 }))
  @IsNumber()
  @IsOptional()
  page?: number = 1;

  @ApiProperty({ 
    example: 10, 
    required: false, 
    default: 10,
    description: "Limit page"
  })
  @Transform(({ value }) => toNumber(value, { default: 10, min: 1 }))
  @IsNumber()
  @IsOptional()
  limit?: number = 10;
  
  @ApiProperty({ 
    required: false, 
    default: "desc",
    description: "Sorting column order (asc, desc)",
    enum: ['asc', 'desc']
  })
  @IsString()
  @IsOptional()
  order?: string = "asc";

  @ApiProperty({ 
    example: "id", 
    required: false, 
    default: "id",
    description: "Sorting column id"
  })
  @IsString()
  @IsOptional()
  orderBy?: string = "id";
}
