import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { IsIn, IsInt, IsOptional, IsString, MinLength, ValidateIf } from 'class-validator';

const ALLOWED_DURATIONS = [3, 7, 14, 30, 60, 90] as const;
export type AdminFeatureDuration = (typeof ALLOWED_DURATIONS)[number];

export class AdminFeatureListingDto {
  @ApiProperty({
    enum: ['feature', 'unfeature'],
    example: 'feature',
    description: 'Bật hoặc gỡ tin nổi bật thủ công',
  })
  @IsIn(['feature', 'unfeature'])
  action!: 'feature' | 'unfeature';

  @ApiPropertyOptional({
    enum: ALLOWED_DURATIONS,
    example: 7,
    description: 'Số ngày featured (bắt buộc khi action=feature)',
  })
  @ValidateIf((o: AdminFeatureListingDto) => o.action === 'feature')
  @Type(() => Number)
  @IsInt()
  @IsIn([...ALLOWED_DURATIONS])
  @IsOptional()
  durationDays?: AdminFeatureDuration;

  @ApiProperty({
    example: 'Đền bù lỗi hiển thị featured trong 3 ngày qua',
    description: 'Lý do cho audit log (tối thiểu 5 ký tự)',
  })
  @IsString()
  @MinLength(5)
  reason!: string;
}
