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 AdsLocation {
  메인하단 = 'ADL001',
  진료정보분석하단 = 'ADL002',
  청구서하단 = 'ADL003',
  고객초대모달 = 'ADL004',
  진료정보모달 = 'ADL005',
}

export enum AdsType {
  이미지 = 'ADT001',
  동영상 = 'ADT002',
}

export enum AdsPlaybackType {
  없음 = 'APT001',
  일회재생 = 'APT002',
  재생시간설정 = 'APT003',
}

export class Advertisement {
  @Expose()
  @ApiProperty({ description: '광고 id' })
  @Transform(({ value }) => typeParser.int(value))
  @IsInt()
  adsId!: number;

  @Expose()
  @ApiPropertyOptional({ description: '기업 ID' })
  @Transform(({ value }) => typeParser.int(value))
  @IsOptional()
  @IsInt()
  agcId?: number;

  @Expose()
  @ApiProperty({ description: '광고명' })
  @IsString()
  adsName!: string;

  @Expose()
  @ApiProperty({
    description:
      '광고위치(ADL001: 메인하단, ADL002: 진료정보분석하단, ADL003: 청구서하단, ADL004: 고객초대모달, ADL005: 진료정보모달)',
    enum: AdsLocation,
  })
  @IsEnum(AdsLocation)
  adsLocation!: AdsLocation;

  @Expose()
  @ApiProperty({
    description: '광고타입(ADT001: 이미지, ADT002: 동영상)',
    enum: AdsType,
  })
  @IsEnum(AdsType)
  adsType!: AdsType;

  @Expose()
  @ApiProperty({
    description: '광고 동영상 URL',
  })
  @IsString()
  @IsOptional()
  adsVideoUrl?: string;

  @Expose()
  @ApiProperty({
    description: '광고 이미지 URL',
  })
  @IsString()
  @IsOptional()
  adsImg?: string;

  @Expose()
  @ApiProperty({ description: '광고랜덤여부(0: 고정, 1: 랜덤)' })
  @Transform(({ value }) => typeParser.int(value))
  @IsIn([0, 1])
  adsRandom!: number;

  @Expose()
  @ApiProperty({ description: '광고정렬(default: 0 | 높은 순서순)' })
  @Transform(({ value }) => typeParser.int(value))
  @IsInt()
  @IsOptional()
  adsSort?: number;

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

  @Expose()
  @ApiProperty({ description: '광고시작일' })
  @IsString()
  adsOpenedAt!: string;

  @Expose()
  @ApiProperty({ description: '광고종료일' })
  @IsString()
  adsClosedAt!: string;

  @Expose()
  @ApiProperty({ description: '광고링크여부(1: 연결 | 0: 미연결, default: 0)' })
  @Transform(({ value }) => typeParser.int(value))
  @IsIn([0, 1])
  @IsOptional()
  adsLinked?: number;

  @Expose()
  @ApiPropertyOptional({ description: '광고외부링크' })
  @IsOptional()
  @IsString()
  adsLink?: string;

  @Expose()
  @ApiPropertyOptional({
    description:
      '광고 기본재생설정(APT001: 없음, APT002: 1회재생, APT003: 재생시간설정)',
    enum: AdsPlaybackType,
  })
  @IsOptional()
  @IsEnum(AdsPlaybackType)
  adsPlaybackType?: AdsPlaybackType;

  @Expose()
  @ApiPropertyOptional({
    description: '광고 재생시간설정',
  })
  @Transform(({ value }) => typeParser.int(value))
  @IsOptional()
  @IsInt()
  adsPlaybackTime?: number;

  @Expose()
  @ApiPropertyOptional({
    description: '누적노출수',
  })
  @Transform(({ value }) => typeParser.int(value))
  @IsOptional()
  @IsInt()
  adsTotalImpressionCount?: number;

  @Expose()
  @ApiPropertyOptional({
    description: '누적노출수',
  })
  @Transform(({ value }) => typeParser.int(value))
  @IsOptional()
  @IsInt()
  adsTotalClickCount?: number;

  @Expose()
  @ApiPropertyOptional({
    description: '누적노출수',
  })
  @Transform(({ value }) => typeParser.int(value))
  @IsOptional()
  @IsInt()
  adsTotalPlayCount?: number;

  @Expose()
  @ApiPropertyOptional({ description: '광고수정일시' })
  @IsOptional()
  @IsString()
  adsUpdatedAt?: string;

  @Expose()
  @ApiProperty({ description: '광고생성일시' })
  @IsString()
  adsCreatedAt!: string;
}
