import { ApiPropertyOptional } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import {
  ArrayMaxSize,
  IsArray,
  IsEnum,
  IsNumber,
  IsOptional,
  IsString,
  IsUrl,
  Length,
  Max,
  Min,
} from 'class-validator';
import { PostVisibility } from '../../../common/enums/post-visibility.enum';
import { toStringArray } from '../../../common/utils/array-transform.util';

export class CreateReelDto {
  @ApiPropertyOptional({ maxLength: 2200, description: 'Reel caption' })
  @IsOptional()
  @IsString()
  @Length(0, 2200)
  content?: string;

  @ApiPropertyOptional({ maxLength: 2200, description: 'Text shown above reel media' })
  @IsOptional()
  @IsString()
  @Length(0, 2200)
  contentTop?: string;

  @ApiPropertyOptional({ maxLength: 2200, description: 'Text shown below reel media' })
  @IsOptional()
  @IsString()
  @Length(0, 2200)
  contentBottom?: string;

  @ApiPropertyOptional({ description: 'Reel video URL (if not uploading videoFile)' })
  @IsOptional()
  @IsUrl({ require_tld: false })
  videoUrl?: string;

  @ApiPropertyOptional({ description: 'Video duration in seconds' })
  @IsOptional()
  @IsNumber()
  @Min(1)
  @Max(7200)
  durationSeconds?: number;

  @ApiPropertyOptional({ description: 'Video thumbnail URL' })
  @IsOptional()
  @IsUrl({ require_tld: false })
  thumbnailUrl?: string;

  @ApiPropertyOptional({ description: 'Music style or genre for the reel', maxLength: 80 })
  @IsOptional()
  @IsString()
  @Length(0, 80)
  style?: string;

  @ApiPropertyOptional({ description: 'Maqam name for the reel', maxLength: 80 })
  @IsOptional()
  @IsString()
  @Length(0, 80)
  maqam?: string;

  @ApiPropertyOptional({ description: 'Rhythm signature like 6/8 for the reel', maxLength: 40 })
  @IsOptional()
  @IsString()
  @Length(0, 40)
  rhythmSignature?: 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[];

  @ApiPropertyOptional({ enum: PostVisibility, default: PostVisibility.PUBLIC })
  @IsOptional()
  @IsEnum(PostVisibility)
  visibility?: PostVisibility;
}
