import { BaseStatusDto } from 'src/core/modules/infrastructure/dto/base-status.dto';
import { RefundEntity } from '../../domain/entities/refund.entity';
import { ApiProperty } from '@nestjs/swagger';
import { IsNumber, IsString, ValidateIf } from 'class-validator';
import { Exclude } from 'class-transformer';
import { TransactionEntity } from 'src/modules/transaction/transaction/domain/entities/transaction.entity';
import { RefundReasonType, RefundType } from '../../constants';

export class RefundDto extends BaseStatusDto implements RefundEntity {
  @ApiProperty({
    type: String,
    required: true,
    example: RefundReasonType.RIDE_MALFUNCTION,
  })
  @IsString()
  refund_reason_type: RefundReasonType;

  @ApiProperty({
    type: String,
    required: false,
    example: '',
  })
  @ValidateIf((object) => object.refund_reason_type == RefundReasonType.OTHER)
  refund_reason: string;

  @ApiProperty({
    type: String,
    required: true,
    example: RefundType.BOOKING,
  })
  @IsString()
  type: RefundType;

  @ApiProperty({
    type: Number,
    required: false,
    example: 1750000,
  })
  refund_sub_total: number;

  @ApiProperty({
    type: Number,
    example: 1750000,
  })
  @IsNumber()
  refund_total: number;

  @ApiProperty({
    type: String,
    required: false,
    example: 'BCA',
  })
  bank_name: string;

  @ApiProperty({
    type: String,
    required: false,
    example: 'andhika',
  })
  bank_account_name: string;

  @ApiProperty({
    type: String,
    required: false,
    example: '64222456',
  })
  bank_account_number: string;

  @ApiProperty({
    type: Object,
    required: true,
    example: {
      id: 'uuid',
      invoice_code: 'INV-',
    },
  })
  transaction: TransactionEntity;

  @Exclude()
  code: string;

  @Exclude()
  request_date: Date;

  @Exclude()
  refund_date: Date;

  @Exclude()
  transaction_id: string;
}
