import { ApiPropertyOptional } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { IsEnum, IsOptional } from 'class-validator';
import { PaginationQueryDto } from '../../../common/dto/pagination-query.dto';

export enum CommentSortBy {
  CREATED_AT = 'createdAt',
  TOP = 'top',
}

export class CommentQueryDto extends PaginationQueryDto {
  @ApiPropertyOptional({
    enum: CommentSortBy,
    default: CommentSortBy.CREATED_AT,
    description: 'Use top for Instagram-like popular comments, or createdAt for chronological sorting',
  })
  @IsOptional()
  @Transform(({ value }) =>
    typeof value === 'string' ? value.trim() : value,
  )
  @IsEnum(CommentSortBy)
  sortBy?: CommentSortBy = CommentSortBy.CREATED_AT;

  @ApiPropertyOptional({
    description: 'Use asc to display oldest comments first, or desc for newest first',
    default: 'desc',
  })
  declare sortOrder: PaginationQueryDto['sortOrder'];
}
