import { IsString, IsEnum, IsNumber, IsDateString, IsOptional, Min, Max } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';

export class CreateCouponDto {
  @ApiProperty({ description: '优惠券名称' })
  @IsString()
  name: string;

  @ApiProperty({ description: '类型', enum: ['fixed', 'percent'] })
  @IsEnum(['fixed', 'percent'])
  type: 'fixed' | 'percent';

  @ApiProperty({ description: '优惠金额/折扣比例' })
  @IsNumber()
  @Min(0)
  value: number;

  @ApiProperty({ description: '最低使用金额' })
  @IsNumber()
  @Min(0)
  minAmount: number;

  @ApiProperty({ description: '发放总量' })
  @IsNumber()
  @Min(1)
  totalCount: number;

  @ApiProperty({ description: '生效日期' })
  @IsDateString()
  startDate: string;

  @ApiProperty({ description: '失效日期' })
  @IsDateString()
  endDate: string;

  @ApiProperty({ description: '适用范围', enum: ['platform', 'merchant', 'room'] })
  @IsEnum(['platform', 'merchant', 'room'])
  scope: 'platform' | 'merchant' | 'room';

  @ApiProperty({ description: '范围关联ID', required: false })
  @IsOptional()
  @IsNumber()
  scopeId?: number;
}

export class UpdateCouponDto {
  @ApiProperty({ description: '优惠券名称', required: false })
  @IsOptional()
  @IsString()
  name?: string;

  @ApiProperty({ description: '状态', enum: ['active', 'paused', 'ended'], required: false })
  @IsOptional()
  @IsEnum(['active', 'paused', 'ended'])
  status?: 'active' | 'paused' | 'ended';

  @ApiProperty({ description: '发放总量', required: false })
  @IsOptional()
  @IsNumber()
  @Min(1)
  totalCount?: number;
}

export class QueryCouponDto {
  @ApiProperty({ description: '页码', required: false, default: 1 })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  @Min(1)
  page?: number = 1;

  @ApiProperty({ description: '每页数量', required: false, default: 10 })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  @Min(1)
  @Max(100)
  pageSize?: number = 10;

  @ApiProperty({ description: '状态', enum: ['active', 'paused', 'ended'], required: false })
  @IsOptional()
  @IsEnum(['active', 'paused', 'ended'])
  status?: 'active' | 'paused' | 'ended';

  @ApiProperty({ description: '适用范围', enum: ['platform', 'merchant', 'room'], required: false })
  @IsOptional()
  @IsEnum(['platform', 'merchant', 'room'])
  scope?: 'platform' | 'merchant' | 'room';

  @ApiProperty({ description: '商家ID', required: false })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  merchantId?: number;

  @ApiProperty({ description: '房源ID', required: false })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  roomId?: number;
}

export class ReceiveCouponDto {
  @ApiProperty({ description: '优惠券ID' })
  @IsNumber()
  couponId: number;
}

export class QueryUserCouponDto {
  @ApiProperty({ description: '状态', enum: ['unused', 'used', 'expired'], required: false })
  @IsOptional()
  @IsEnum(['unused', 'used', 'expired'])
  status?: 'unused' | 'used' | 'expired';

  @ApiProperty({ description: '页码', required: false, default: 1 })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  @Min(1)
  page?: number = 1;

  @ApiProperty({ description: '每页数量', required: false, default: 10 })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  @Min(1)
  @Max(100)
  pageSize?: number = 10;
}
