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

export enum Order {
  Desc = 'DESC',
  Asc = 'ASC',
}

@ApiExtraModels()
export class PagingReqDto {
  @ApiProperty({ example: 'abc', required: false, type: String })
  @IsOptional()
  @IsString()
  search? = '';

  @ApiProperty({ example: 20, required: false, type: Number })
  @IsOptional()
  @IsNumber()
  @Min(0)
  @Max(100)
  @Type(() => Number)
  pageSize = 10;

  @ApiProperty({ example: 20, required: false, type: Number })
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  @Min(1)
  pageNumber = 1;

  @ApiProperty({
    name: 'sort',
    type: 'object',
    additionalProperties: { type: 'string' },
    description: 'Data object with key-value pairs',
    required: false,
    example: {
      created_at: 'asc',
    },
  })
  @IsOptional()
  sort: Record<string, string> = {
    created_at: 'asc',
  };
}

export class PagingRes {
  @ApiProperty({ example: 100 })
  pages: number;

  @ApiProperty({ example: 1000 })
  count: number;

  @ApiProperty({ example: 5 })
  pageNumber: number;
}
