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

export class FindDealsDto {
  @ApiPropertyOptional({ description: 'Cursor for pagination' })
  @IsString()
  @IsOptional()
  cursor?: string;

  @ApiPropertyOptional({ default: 20, minimum: 1, maximum: 100 })
  @Type(() => Number)
  @IsInt()
  @Min(1)
  @Max(100)
  @IsOptional()
  limit?: number = 20;

  @ApiPropertyOptional()
  @IsUUID()
  @IsOptional()
  pipelineId?: string;

  @ApiPropertyOptional()
  @IsUUID()
  @IsOptional()
  stageId?: string;

  @ApiPropertyOptional()
  @IsUUID()
  @IsOptional()
  assigneeId?: string;

  @ApiPropertyOptional({ enum: CrmDealSource })
  @IsEnum(CrmDealSource)
  @IsOptional()
  source?: CrmDealSource;

  @ApiPropertyOptional({ description: 'Search by title or contact name' })
  @IsString()
  @IsOptional()
  search?: string;

  @ApiPropertyOptional()
  @IsDateString()
  @IsOptional()
  dateFrom?: string;

  @ApiPropertyOptional()
  @IsDateString()
  @IsOptional()
  dateTo?: string;

  @ApiPropertyOptional({
    description: 'View mode',
    enum: ['list', 'kanban'],
    default: 'list',
  })
  @IsString()
  @IsOptional()
  view?: 'list' | 'kanban' = 'list';
}
