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

export class ScanRedemptionDto {
  @ApiProperty({ description: 'QR code content' })
  @IsString()
  @MaxLength(1000)
  qrCode: string;

  @ApiPropertyOptional({ description: 'Store ID where redemption occurs' })
  @IsOptional()
  @IsUUID()
  storeId?: string;
}

export class ManualRedemptionDto {
  @ApiProperty({ description: 'Coupon code for manual entry' })
  @IsString()
  @MaxLength(200)
  couponCode: string;

  @ApiPropertyOptional()
  @IsOptional()
  @IsUUID()
  storeId?: string;
}

export class BatchRedemptionDto {
  @ApiProperty({ type: [String], description: 'Array of coupon codes' })
  @IsArray()
  @IsString({ each: true })
  couponCodes: string[];

  @ApiPropertyOptional()
  @IsOptional()
  @IsUUID()
  storeId?: string;
}

export class ListRedemptionsQueryDto {
  @ApiPropertyOptional({ default: 1 })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  page?: number = 1;

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

  @ApiPropertyOptional({ description: 'ISO 8601 date string' })
  @IsOptional()
  @IsDateString()
  startDate?: string;

  @ApiPropertyOptional({ description: 'ISO 8601 date string' })
  @IsOptional()
  @IsDateString()
  endDate?: string;
}
