import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsEnum, IsOptional, IsString } from 'class-validator';
import { PaginationQueryDto } from '../../../common/dto/pagination-query.dto';
import { PostType } from '../../../common/enums/post-type.enum';
import { PostVisibility } from '../../../common/enums/post-visibility.enum';

export const POST_SORT_FIELDS = [
  'createdAt',
  'updatedAt',
  'likesCount',
  'commentsCount',
  'savesCount',
  'shareCount',
  'viewCount',
  'playCount',
] as const;

export type PostSortField = (typeof POST_SORT_FIELDS)[number];

export class PostQueryDto extends PaginationQueryDto {
  @ApiPropertyOptional({ enum: PostVisibility })
  @IsOptional()
  @IsEnum(PostVisibility)
  visibility?: PostVisibility;

  @ApiPropertyOptional({ enum: PostType })
  @IsOptional()
  @IsEnum(PostType)
  postType?: PostType;

  @ApiPropertyOptional({ description: 'Search inside post content' })
  @IsOptional()
  @IsString()
  q?: string;

  @ApiPropertyOptional({ description: 'Filter by hashtag without the # prefix', example: 'music' })
  @IsOptional()
  @IsString()
  hashtag?: string;

  @ApiPropertyOptional({ enum: POST_SORT_FIELDS, default: 'createdAt' })
  @IsOptional()
  @IsEnum(POST_SORT_FIELDS)
  sortBy?: PostSortField;
}
