import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { ArrayMaxSize, IsArray, IsMongoId, IsOptional, IsString, Length } from 'class-validator';
import { toStringArray } from '../../../common/utils/array-transform.util';

export class CreateCommentDto {
  @ApiProperty()
  @IsMongoId()
  postId!: string;

  @ApiProperty()
  @IsString()
  @Length(1, 1000)
  content!: string;

  @ApiPropertyOptional()
  @IsOptional()
  @IsMongoId()
  parentCommentId?: string;

  @ApiPropertyOptional({ type: [String], description: 'Mention usernames like rami_sabry (max 30)' })
  @IsOptional()
  @Transform(toStringArray)
  @IsArray()
  @ArrayMaxSize(30)
  @IsString({ each: true })
  @Length(1, 30, { each: true })
  mentionUsernames?: string[];
}
