import { ApiProperty } from '@nestjs/swagger';
import { IsIn, IsNotEmpty, IsOptional, Validate } from 'class-validator';
import { IsNotExist } from '../../../utils/validators/is-not-exists.validator';
import { AvailableSection } from '../entities/discount.entity';

export class UpdateDiscountDto {
  @ApiProperty({ example: '' })
  @IsNotEmpty()
  id: number;

  @ApiProperty({ example: '' })
  @IsOptional()
  name: string;

  @ApiProperty({ example: '' })
  @IsOptional()
  customerId: number;

  @ApiProperty({ example: '' })
  @IsOptional()
  userId: string;

  @ApiProperty({ example: '' })
  @IsOptional()
  discountPercentage: number;

  @ApiProperty({ example: '' })
  @IsOptional()
  discountAmount: number;

  @ApiProperty({ example: '' })
  @IsOptional()
  @Validate(IsNotExist, ['DiscountEntity'], {
    message: 'این کوپن تخفیف قبلا رزرو شده، یک کد تخفیف دیگر وارد نمایید',
  })
  couponCode: string;

  @ApiProperty({ example: '' })
  @IsOptional()
  startDate: Date | null;

  @ApiProperty({ example: '' })
  @IsOptional()
  endDate: Date | null;

  @ApiProperty({ example: 1, enum: AvailableSection })
  @IsOptional()
  @IsIn(Object.values(AvailableSection))
  section: AvailableSection;

  @ApiProperty()
  @IsOptional()
  promotionPlanId?: number | null;
}
