import { IsNotEmpty, IsString, IsEnum, IsNumber, IsOptional, IsBoolean, IsDateString, Min, IsArray, } from 'class-validator'; import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { Type } from 'class-transformer'; import { CouponType } from '../interface/coupon'; export class CreateCouponDto { @IsNotEmpty() @IsString() @ApiProperty({ example: 'DISCOUNT10', description: 'Unique coupon code' }) code!: string; @IsNotEmpty() @IsString() @ApiProperty({ example: '10% Off', description: 'Coupon name' }) name!: string; @IsOptional() @IsString() @ApiPropertyOptional({ example: 'Get 10% off on your order', description: 'Coupon description' }) description?: string; @IsNotEmpty() @IsEnum(CouponType) @ApiProperty({ enum: CouponType, example: CouponType.PERCENTAGE, description: 'Coupon type' }) type!: CouponType; @IsNotEmpty() @IsNumber() @Min(0) @Type(() => Number) @ApiProperty({ example: 10, description: 'Discount value (amount or percentage)' }) value!: number; @IsOptional() @IsNumber() @Min(0) @Type(() => Number) @ApiPropertyOptional({ example: 50000, description: 'Maximum discount amount (for percentage coupons)' }) maxDiscount?: number; @IsOptional() @IsNumber() @Min(0) @Type(() => Number) @ApiPropertyOptional({ example: 100000, description: 'Minimum order amount to use coupon' }) minOrderAmount?: number; @IsOptional() @IsNumber() @Min(1) @Type(() => Number) @ApiPropertyOptional({ example: 100, description: 'Maximum number of times coupon can be used' }) maxUses?: number; @IsOptional() @IsNumber() @Min(1) @Type(() => Number) @ApiPropertyOptional({ example: 1, description: 'Maximum uses per user' }) maxUsesPerUser?: number; @IsOptional() @IsDateString() @ApiPropertyOptional({ example: '2024-01-01T00:00:00Z', description: 'Coupon validity start date' }) startDate?: string; @IsOptional() @IsDateString() @ApiPropertyOptional({ example: '2024-12-31T23:59:59Z', description: 'Coupon validity end date' }) endDate?: string; @IsOptional() @IsBoolean() @Type(() => Boolean) @ApiPropertyOptional({ example: true, description: 'Whether coupon is active' }) isActive?: boolean; @IsOptional() @IsArray() @IsString({ each: true }) @ApiPropertyOptional({ example: ['category-id-1', 'category-id-2'], description: 'Array of product category IDs. If empty, coupon applies to all categories.', type: [String], }) foodCategories?: string[]; @IsOptional() @IsArray() @IsString({ each: true }) @ApiPropertyOptional({ example: ['product-id-1', 'product-id-2'], description: 'Array of product IDs. If empty, coupon applies to all products.', type: [String], }) products?: string[]; @IsOptional() @IsString() @ApiPropertyOptional({ example: '09123456789', description: 'Phone number of the user who can use this coupon. If empty, coupon can be used by any user.', }) userPhone?: string; }