import { IsString, IsOptional, IsBoolean, IsNumber, IsEnum, ValidateIf, IsNotEmpty } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { PaymentMethodEnum, PaymentGatewayEnum } from '../interface/payment';

export class CreatePaymentMethodDto {

  @ApiProperty({ description: 'Payment method', enum: PaymentMethodEnum })
  @IsEnum(PaymentMethodEnum)
  method!: PaymentMethodEnum;

  @ApiProperty({ description: 'Payment gateway', enum: PaymentGatewayEnum, required: false })
  @IsOptional()
  @IsEnum(PaymentGatewayEnum)
  gateway?: PaymentGatewayEnum | null;

  @ApiProperty({ description: 'Payment method description', required: false })
  @IsOptional()
  @IsString()
  description?: string;

  @ApiProperty({ description: 'Card number for card-to-card payments', required: false })
  @IsOptional()
  @IsString()
  cardNumber?: string;

  @ApiProperty({ description: 'Second card number for card-to-card payments', required: false })
  @IsOptional()
  @IsString()
  cardNumber2?: string;

  @ApiProperty({ description: 'Third card number for card-to-card payments', required: false })
  @IsOptional()
  @IsString()
  cardNumber3?: string;

  @ApiProperty({ description: 'Card owner name for card-to-card payments', required: false })
  @ValidateIf((dto: CreatePaymentMethodDto) => dto.method === PaymentMethodEnum.CreditCard)
  @IsNotEmpty()
  @IsString()
  cardOwner?: string;

  @ApiProperty({ description: 'Second card owner name for card-to-card payments', required: false })
  @IsOptional()
  @IsString()
  cardOwner2?: string;

  @ApiProperty({ description: 'Third card owner name for card-to-card payments', required: false })
  @IsOptional()
  @IsString()
  cardOwner3?: string;

  @ApiProperty({ description: 'Is payment method enabled', required: false, default: true })
  @IsOptional()
  @IsBoolean()
  enabled?: boolean;

  @ApiProperty({ description: 'Display order', required: false, default: 0 })
  @IsOptional()
  @IsNumber()
  order?: number;

  @ApiProperty({ description: 'Merchant ID', required: false })
  @IsOptional()
  @IsString()
  merchantId?: string;
}
