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 BannerLocationType {
  메인 = 'BNN001',
  하단 = 'BNN002',
}

export class Banner {
  @Expose()
  @ApiProperty({ description: '배너id' })
  @Transform(({ value }) => typeParser.int(value))
  @IsInt()
  bnnId!: number;

  @Expose()
  @ApiProperty({ description: '배너위치타입(BNN001: 메인 | BNN002:하단)' })
  @IsEnum(BannerLocationType)
  bnnLocationType!: BannerLocationType;

  @Expose()
  @ApiProperty({ description: '배너명' })
  @IsString()
  bnnName!: string;

  @Expose()
  @ApiPropertyOptional({ description: '배너제목' })
  @IsString()
  @IsOptional()
  bnnTitle?: string;

  @Expose()
  @ApiPropertyOptional({ description: '배너정렬(default:0 / 높은순서순)' })
  @Transform(({ value }) => typeParser.int(value))
  @IsInt()
  @IsOptional()
  bnnSort?: number;

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

  @Expose()
  @ApiProperty({ description: '배너링크여부(default:0, 연결:1|미연결:0)' })
  @Transform(({ value }) => typeParser.int(value))
  @IsInt()
  @IsIn([0, 1])
  bnnLinked!: number;

  @Expose()
  @ApiPropertyOptional({ description: '배너링크' })
  @IsString()
  @IsOptional()
  bnnLink?: string;

  @Expose()
  @ApiProperty({ description: '배너이미지' })
  @IsString()
  bnnImg!: string;

  @Expose()
  @ApiPropertyOptional({ description: '배너시작일시' })
  @IsString()
  @IsOptional()
  bnnOpenedAt?: string;

  @Expose()
  @ApiPropertyOptional({ description: '배너종료일시' })
  @IsString()
  @IsOptional()
  bnnClosedAt?: string;

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

  @Expose()
  @ApiProperty({ description: '배너생성일시' })
  @IsString()
  bnnCreatedAt!: string;
}
