import {
  IsOptional,
  IsString,
  IsUUID,
  IsInt,
  IsEnum,
  Min,
  Max,
} from 'class-validator';
import { Type } from 'class-transformer';
import { ApiPropertyOptional } from '@nestjs/swagger';

export enum ClientSortBy {
  CREATED_AT = 'createdAt',
  LAST_NAME = 'lastName',
  LAST_ACTIVITY_AT = 'lastActivityAt',
}

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

export class FindClientsDto {
  @ApiPropertyOptional({
    description: 'Cursor for pagination (UUID of last item)',
    example: '550e8400-e29b-41d4-a716-446655440000',
  })
  @IsUUID()
  @IsOptional()
  cursor?: string;

  @ApiPropertyOptional({
    description: 'Number of items to return (1-100)',
    default: 20,
    minimum: 1,
    maximum: 100,
  })
  @Type(() => Number)
  @IsInt()
  @Min(1)
  @Max(100)
  @IsOptional()
  limit?: number = 20;

  @ApiPropertyOptional({
    description: 'Search by name or phone',
    example: 'Иван',
  })
  @IsString()
  @IsOptional()
  search?: string;

  @ApiPropertyOptional({
    description: 'Filter by assigned trainer UUID',
    example: '550e8400-e29b-41d4-a716-446655440000',
  })
  @IsUUID()
  @IsOptional()
  assignedTrainerId?: string;

  @ApiPropertyOptional({
    description: 'Sort field',
    enum: ClientSortBy,
    default: ClientSortBy.CREATED_AT,
  })
  @IsEnum(ClientSortBy)
  @IsOptional()
  sortBy?: ClientSortBy = ClientSortBy.CREATED_AT;

  @ApiPropertyOptional({
    description: 'Sort order',
    enum: SortOrder,
    default: SortOrder.DESC,
  })
  @IsEnum(SortOrder)
  @IsOptional()
  sortOrder?: SortOrder = SortOrder.DESC;
}
