import {
  IsString,
  IsEnum,
  IsBoolean,
  IsOptional,
  IsInt,
  Min,
  Max,
} from 'class-validator';
import { ApiPropertyOptional } from '@nestjs/swagger';
import { Transform, Type } from 'class-transformer';
import { IntegrationType, SyncStatus } from '@prisma/client';

/**
 * DTO for querying integration credentials with filtering and pagination
 */
export class QueryCredentialsDto {
  @ApiPropertyOptional({
    description: 'Filter by integration type',
    enum: IntegrationType,
    example: IntegrationType.PLENTYONE,
  })
  @IsEnum(IntegrationType)
  @IsOptional()
  type?: IntegrationType;

  @ApiPropertyOptional({
    description: 'Filter by active status',
    example: true,
  })
  @IsBoolean()
  @IsOptional()
  @Transform(({ value }) => value === 'true' || value === true)
  isActive?: boolean;

  @ApiPropertyOptional({
    description: 'Filter by sync status',
    enum: SyncStatus,
    example: SyncStatus.SUCCESS,
  })
  @IsEnum(SyncStatus)
  @IsOptional()
  syncStatus?: SyncStatus;

  @ApiPropertyOptional({
    description: 'Search by name',
    example: 'Production',
  })
  @IsString()
  @IsOptional()
  search?: string;

  @ApiPropertyOptional({
    description: 'Page number (1-based)',
    example: 1,
    default: 1,
  })
  @Type(() => Number)
  @IsInt()
  @Min(1)
  @IsOptional()
  page?: number = 1;

  @ApiPropertyOptional({
    description: 'Items per page',
    example: 10,
    default: 10,
  })
  @Type(() => Number)
  @IsInt()
  @Min(1)
  @Max(100)
  @IsOptional()
  limit?: number = 10;
}
