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

export enum ProductType {
  구독상품 = 'PRD001',
  체험상품 = 'PRD002',
  기업상품 = 'PRD003',
}

export enum ProductCycleType {
  월구독 = 'PCY001',
  연구독 = 'PCY002',
  일구독 = 'PCY003',
}

export class Product {
  @Expose()
  @ApiProperty({ description: '상품id' })
  @IsInt()
  prdId!: number;

  @Expose()
  @ApiProperty({
    description:
      '상품타입(PRD001: 구독상품 | PRD002:체험험상품 | PRD003:기업상품)',
  })
  @IsEnum(ProductType)
  prdType!: ProductType;

  @Expose()
  @ApiProperty({
    description: '결제주기타입(PCY001: 월구독| PCY002:연구독 | PCY003:일구독)',
  })
  @IsEnum(ProductCycleType)
  prdPaymentType!: ProductCycleType;

  @Expose()
  @ApiProperty({
    description: '이용주기타입(PCY001: 월구독| PCY002:연구독 | PCY003:일구독)',
  })
  @IsEnum(ProductCycleType)
  prdUseType!: ProductCycleType;

  @Expose()
  @ApiProperty({ description: '결제주기' })
  @IsInt()
  prdPaymentCycle!: number;

  @Expose()
  @ApiProperty({ description: '이용주기' })
  @IsInt()
  prdUseCycle!: number;

  @Expose()
  @ApiProperty({ description: '상품코드' })
  @IsString()
  prdCode!: string;

  @ApiProperty({ description: '상품명' })
  @IsString()
  @Expose()
  prdName!: string;

  @Expose()
  @ApiPropertyOptional({ description: '상품설명' })
  @IsString()
  @IsOptional()
  prdContent?: string;

  @Expose()
  @ApiPropertyOptional({ description: '상품 이미지' })
  @IsString()
  @IsOptional()
  prdImg?: string;

  @Expose()
  @ApiProperty({ description: '이용제한수량' })
  @IsInt()
  prdLimitedQty!: number;

  @Expose()
  @ApiProperty({ description: '상품소비자가격' })
  @IsInt()
  prdConsumerPrice!: number;

  @Expose()
  @ApiProperty({ description: '상품판매가격' })
  @IsInt()
  prdSalePrice!: number;

  @Expose()
  @ApiProperty({ description: '상품정렬(default:0 / 높은순서순)' })
  @Transform(({ value }) => typeParser.int(value))
  @IsInt()
  prdSort!: number;

  @Expose()
  @ApiProperty({ description: '상품추천여부(default:0, 추천:1|미추천:0)' })
  @Transform(({ value }) => typeParser.int(value))
  @IsIn([0, 1])
  prdRecommend!: number;

  @Expose()
  @ApiProperty({ description: '상품노출여부(default:1, 노출:1|비노출:0)' })
  @Transform(({ value }) => typeParser.int(value))
  @IsIn([0, 1])
  prdShow!: number;

  @Expose()
  @ApiProperty({ description: '매월 지급 포인트(default:0)' })
  @Transform(({ value }) => typeParser.int(value))
  @IsInt()
  prdMonthlyPoint!: number;

  @Expose()
  @ApiPropertyOptional({ description: '유의사항' })
  @IsString()
  @IsOptional()
  prdCaution?: string;

  @Expose()
  @ApiPropertyOptional({ description: '상품수정일시' })
  @IsString()
  @IsOptional()
  prdUpdatedAt?: string;

  @Expose()
  @ApiProperty({ description: '상품생성일시' })
  @IsString()
  prdCreatedAt!: string;
}
