import { IsOptional, IsEnum, IsDateString, IsNumber, Min, Max, IsString } from 'class-validator';
import { Type } from 'class-transformer';
import { ApiProperty } from '@nestjs/swagger';
import { RequestStatus } from '../enums/request-status.enum';
import { RequestType } from '../enums/request-type.enum';

export class RequestQueryDto {
  @ApiProperty({
    description: 'Filter by request status',
    enum: RequestStatus,
    required: false,
  })
  @IsOptional()
  @IsEnum(RequestStatus)
  status?: RequestStatus;

  @ApiProperty({
    description: 'Filter by request type',
    enum: RequestType,
    required: false,
  })
  @IsOptional()
  @IsEnum(RequestType)
  requestType?: RequestType;

  @ApiProperty({
    description: 'Filter by applicant ID',
    required: false,
  })
  @IsOptional()
  @IsString()
  applicantId?: string;

  @ApiProperty({
    description: 'Filter by request number',
    required: false,
  })
  @IsOptional()
  @IsString()
  requestNumber?: string;

  @ApiProperty({
    description: 'Filter by workflow code',
    required: false,
  })
  @IsOptional()
  @IsString()
  workflowCode?: string;

  @ApiProperty({
    description: 'Filter by department code',
    required: false,
  })
  @IsOptional()
  @IsString()
  departmentCode?: string;

  @ApiProperty({
    description: 'Start date for date range filter (ISO 8601)',
    required: false,
    example: '2024-01-01T00:00:00Z',
  })
  @IsOptional()
  @IsDateString()
  startDate?: string;

  @ApiProperty({
    description: 'End date for date range filter (ISO 8601)',
    required: false,
    example: '2024-12-31T23:59:59Z',
  })
  @IsOptional()
  @IsDateString()
  endDate?: string;

  @ApiProperty({
    description: 'Page number for pagination (1-indexed)',
    required: false,
    default: 1,
    minimum: 1,
  })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  @Min(1)
  page?: number = 1;

  @ApiProperty({
    description: 'Number of items per page',
    required: false,
    default: 20,
    minimum: 1,
    maximum: 100,
  })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  @Min(1)
  limit?: number = 20;

  @ApiProperty({
    description: 'Sort field',
    required: false,
    default: 'createdAt',
    enum: ['createdAt', 'updatedAt', 'requestNumber', 'status'],
  })
  @IsOptional()
  @IsString()
  sortBy?: string = 'createdAt';

  @ApiProperty({
    description: 'Sort order',
    required: false,
    default: 'DESC',
    enum: ['ASC', 'DESC'],
  })
  @IsOptional()
  @IsString()
  sortOrder?: 'ASC' | 'DESC' = 'DESC';
}
