import { typeParser } from '@lib/utils/type-parser';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Expose, Transform } from 'class-transformer';
import { IsEnum, IsInt, IsOptional, IsString } from 'class-validator';

export enum PaymentState {
  결제완료 = 'PAY001',
  결제취소 = 'PAY002',
  결제실패 = 'PAY003',
}

export enum PaymentMethod {
  PG = 'PMT001',
  현금 = 'PMT002',
  무료 = 'PMT003',
}

export class Payment {
  @Expose()
  @ApiProperty({ description: 'payment id' })
  @Transform(({ value }) => typeParser.int(value))
  @IsInt()
  pmtId!: number;

  @Expose()
  @ApiProperty({
    description: `결제상태(결제완료 : PAY001 | 결제취소 : PAY002 |결제실패 : PAY003 )`,
    enum: PaymentState,
  })
  @IsEnum(PaymentState)
  pmtState!: PaymentState;

  @Expose()
  @ApiProperty({
    description: `결제수단(PG : PMT001 | 현금 : PMT002 |무료료 : PMT003 )`,
    enum: PaymentMethod,
  })
  @IsEnum(PaymentMethod)
  pmtMethod!: PaymentMethod;

  @Expose()
  @ApiProperty({ description: '거래번호(toss)' })
  @IsString()
  pmtTid!: string;

  @Expose()
  @ApiPropertyOptional({ description: '결제금액' })
  @IsInt()
  @IsOptional()
  pmtAmount?: number;

  @Expose()
  @ApiPropertyOptional({ description: '결제카드회사명' })
  @IsString()
  @IsOptional()
  pmtCardName?: string;

  @Expose()
  @ApiPropertyOptional({ description: '결제카드타입' })
  @IsString()
  @IsOptional()
  pmtCardType?: string;

  @Expose()
  @ApiPropertyOptional({ description: '결제카드번호' })
  @IsString()
  @IsOptional()
  pmtCardNumber?: string;

  @Expose()
  @ApiPropertyOptional({ description: '결제카드빌링키' })
  @IsString()
  @IsOptional()
  pmtCardBillingKey?: string;

  @Expose()
  @ApiPropertyOptional({ description: `결제실패/취소사유(최대200자)` })
  @IsString()
  @IsOptional()
  pmtReason?: string;

  @Expose()
  @ApiPropertyOptional({ description: 'PG결제승인일시' })
  @IsString()
  @IsOptional()
  pmtApprovedAt?: string;

  @Expose()
  @ApiPropertyOptional({ description: '결제취소일시' })
  @IsString()
  @IsOptional()
  pmtCanceledAt?: string;

  @Expose()
  @ApiPropertyOptional({ description: '결제수정일시' })
  @IsString()
  @IsOptional()
  pmtUpdatedAt?: string;

  @Expose()
  @ApiProperty({ description: '결제생성일시' })
  @IsString()
  pmtCreatedAt!: string;
}
