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

export class CreateCouponDto {
  @ApiProperty({ maxLength: 200 })
  @IsString()
  @MaxLength(200)
  name: string;

  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  description?: string;

  @ApiProperty({ enum: ['discount', 'voucher', 'gift_card', 'loyalty'] })
  @IsString()
  type: string;

  @ApiProperty()
  @IsString()
  @MaxLength(50)
  category: string;

  @ApiProperty({ minimum: 0.01 })
  @IsNumber()
  @Min(0.01)
  faceValue: number;

  @ApiProperty({ minimum: 0.01 })
  @IsNumber()
  @Min(0.01)
  price: number;

  @ApiProperty({ minimum: 1 })
  @IsNumber()
  @IsInt()
  @Min(1)
  totalSupply: number;

  @ApiPropertyOptional({ maxLength: 500 })
  @IsOptional()
  @IsString()
  @MaxLength(500)
  imageUrl?: string;

  @ApiProperty({ description: 'ISO 8601 date string' })
  @IsDateString()
  validFrom: string;

  @ApiProperty({ description: 'ISO 8601 date string' })
  @IsDateString()
  validUntil: string;

  @ApiPropertyOptional({ default: true })
  @IsOptional()
  @IsBoolean()
  isTradable?: boolean;

  @ApiPropertyOptional({ default: true })
  @IsOptional()
  @IsBoolean()
  isTransferable?: boolean;

  @ApiPropertyOptional({ type: [Object] })
  @IsOptional()
  @IsArray()
  rules?: any[];
}

export class UpdateCouponStatusDto {
  @ApiProperty({ enum: ['minted', 'listed', 'sold', 'in_circulation', 'redeemed', 'expired', 'recalled'] })
  @IsString()
  status: string;
}

export class PurchaseCouponDto {
  @ApiPropertyOptional({ default: 1, minimum: 1 })
  @IsOptional()
  @IsNumber()
  @IsInt()
  @Min(1)
  quantity?: number = 1;
}

export class ListCouponsQueryDto {
  @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()
  @IsOptional()
  @IsString()
  category?: string;

  @ApiPropertyOptional({ enum: ['minted', 'listed', 'sold', 'in_circulation', 'redeemed', 'expired', 'recalled'] })
  @IsOptional()
  @IsString()
  status?: string;

  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  search?: string;

  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  issuerId?: string;
}

export class RejectCouponDto {
  @ApiProperty({ description: 'Reason for rejecting the coupon' })
  @IsString()
  @MaxLength(1000)
  reason: string;
}

export class FlagStoreDto {
  @ApiProperty({ description: 'Reason for flagging the store' })
  @IsString()
  @MaxLength(1000)
  reason: string;
}
