import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
  IsString,
  IsNotEmpty,
  IsOptional,
  IsEnum,
  IsInt,
  Min,
  Max,
  MaxLength,
  Matches,
} from 'class-validator';

export enum AspectRatioDto {
  PORTRAIT_9_16 = 'PORTRAIT_9_16',
  SQUARE_1_1 = 'SQUARE_1_1',
  LANDSCAPE_16_9 = 'LANDSCAPE_16_9',
}

/**
 * Video stili artık serbest string olarak kabul ediliyor.
 * Frontend'de 50+ stil tanımlı (CINEMATIC, ANIME, NOIR, CYBERPUNK vb.).
 * Enum kısıtlaması kaldırıldı — yeni stiller eklendiğinde backend güncellemesi gerekmez.
 */

export class CreateProjectDto {
  @ApiProperty({ description: 'Proje başlığı', example: 'Boötes Boşluğu' })
  @IsString()
  @IsNotEmpty()
  @MaxLength(200)
  title: string;

  @ApiPropertyOptional({ description: 'Proje açıklaması' })
  @IsString()
  @IsOptional()
  @MaxLength(1000)
  description?: string;

  @ApiProperty({
    description: 'Video üretim promptu — AI bu metni kullanarak senaryo üretir',
    example: 'Boötes Boşluğu — evrendeki en büyük boşluk',
  })
  @IsString()
  @IsNotEmpty()
  @MaxLength(2000)
  prompt: string;

  @ApiPropertyOptional({
    description: 'Senaryo ve TTS hedef dili (ISO 639-1)',
    example: 'tr',
    default: 'tr',
  })
  @IsString()
  @IsOptional()
  language?: string;

  @ApiPropertyOptional({
    description: 'En-boy oranı',
    enum: AspectRatioDto,
    default: AspectRatioDto.PORTRAIT_9_16,
  })
  @IsEnum(AspectRatioDto)
  @IsOptional()
  aspectRatio?: AspectRatioDto;

  @ApiPropertyOptional({
    description: 'Video stili (CINEMATIC, DOCUMENTARY, ANIME, NOIR, CYBERPUNK vb.)',
    example: 'CINEMATIC',
    default: 'CINEMATIC',
  })
  @IsString()
  @IsOptional()
  @MaxLength(50)
  videoStyle?: string;

  @ApiPropertyOptional({ description: 'Sinematik stil referansı (örn: Wes Anderson, Matrix)' })
  @IsString()
  @IsOptional()
  @MaxLength(200)
  cinematicReference?: string;

  @ApiPropertyOptional({
    description: 'Hedef video süresi (saniye)',
    example: 60,
    default: 60,
  })
  @IsInt()
  @IsOptional()
  @Min(15)
  @Max(180)
  targetDuration?: number;

  @ApiPropertyOptional({
    description: 'SEO hedef anahtar kelimeler',
    example: ['ai video', 'youtube shorts'],
  })
  @IsOptional()
  seoKeywords?: string[];

  @ApiPropertyOptional({
    description: 'Referans video URL (stil ilhamı için)',
    example: 'https://youtube.com/shorts/abc123',
  })
  @IsString()
  @IsOptional()
  referenceUrl?: string;
}

export class UpdateProjectDto {
  @ApiPropertyOptional({ description: 'Proje başlığı' })
  @IsString()
  @IsOptional()
  @MaxLength(200)
  title?: string;

  @ApiPropertyOptional({ description: 'Proje açıklaması' })
  @IsString()
  @IsOptional()
  @MaxLength(1000)
  description?: string;

  @ApiPropertyOptional({ description: 'Video üretim promptu' })
  @IsString()
  @IsOptional()
  @MaxLength(2000)
  prompt?: string;

  @ApiPropertyOptional({ description: 'Hedef dil (ISO 639-1)' })
  @IsString()
  @IsOptional()
  language?: string;

  @ApiPropertyOptional({ enum: AspectRatioDto })
  @IsEnum(AspectRatioDto)
  @IsOptional()
  aspectRatio?: AspectRatioDto;

  @ApiPropertyOptional({
    description: 'Video stili (CINEMATIC, DOCUMENTARY, ANIME, NOIR, CYBERPUNK vb.)',
  })
  @IsString()
  @IsOptional()
  @MaxLength(50)
  videoStyle?: string;

  @ApiPropertyOptional({ description: 'Sinematik stil referansı (örn: Wes Anderson, Matrix)' })
  @IsString()
  @IsOptional()
  @MaxLength(200)
  cinematicReference?: string;

  @ApiPropertyOptional({ description: 'Hedef video süresi (saniye)' })
  @IsInt()
  @IsOptional()
  @Min(15)
  @Max(180)
  targetDuration?: number;
}

/**
 * X/Twitter tweet URL'sinden proje oluşturma DTO'su.
 * Tweet içeriği otomatik olarak prompt'a dönüştürülür.
 */
export class CreateFromTweetDto {
  @ApiProperty({
    description: 'X/Twitter tweet URL\'si',
    example: 'https://x.com/elonmusk/status/1893456789012345678',
  })
  @IsString()
  @IsNotEmpty({ message: 'Tweet URL\'si boş olamaz' })
  @Matches(
    /^https?:\/\/(x\.com|twitter\.com)\/([\w]+\/status\/\d+|i\/status\/\d+)/,
    { message: 'Geçerli bir X/Twitter tweet URL\'si girin' },
  )
  tweetUrl: string;

  @ApiPropertyOptional({
    description: 'Proje başlığı (boş bırakılırsa tweet\'ten otomatik üretilir)',
  })
  @IsString()
  @IsOptional()
  @MaxLength(200)
  title?: string;

  @ApiPropertyOptional({
    description: 'Hedef video dili (ISO 639-1)',
    default: 'tr',
  })
  @IsString()
  @IsOptional()
  language?: string;

  @ApiPropertyOptional({ enum: AspectRatioDto, default: AspectRatioDto.PORTRAIT_9_16 })
  @IsEnum(AspectRatioDto)
  @IsOptional()
  aspectRatio?: AspectRatioDto;

  @ApiPropertyOptional({
    description: 'Video stili (CINEMATIC, DOCUMENTARY, ANIME, NOIR, CYBERPUNK vb.)',
    default: 'CINEMATIC',
  })
  @IsString()
  @IsOptional()
  @MaxLength(50)
  videoStyle?: string;

  @ApiPropertyOptional({ description: 'Sinematik stil referansı (örn: Wes Anderson, Matrix)' })
  @IsString()
  @IsOptional()
  @MaxLength(200)
  cinematicReference?: string;

  @ApiPropertyOptional({ description: 'Hedef video süresi (saniye)', default: 60 })
  @IsInt()
  @IsOptional()
  @Min(15)
  @Max(180)
  targetDuration?: number;
}

export class CreateFromYoutubeDto {
  @ApiProperty({
    description: 'YouTube Video URL\'si',
    example: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
  })
  @IsString()
  @IsNotEmpty({ message: 'YouTube URL\'si boş olamaz' })
  @Matches(
    /^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.be)\/.+$/,
    { message: 'Geçerli bir YouTube URL\'si girin' },
  )
  youtubeUrl: string;

  @ApiPropertyOptional({
    description: 'Proje başlığı (boş bırakılırsa YouTube\'dan otomatik üretilir)',
  })
  @IsString()
  @IsOptional()
  @MaxLength(200)
  title?: string;

  @ApiPropertyOptional({
    description: 'Hedef video dili (ISO 639-1)',
    default: 'tr',
  })
  @IsString()
  @IsOptional()
  language?: string;

  @ApiPropertyOptional({ enum: AspectRatioDto, default: AspectRatioDto.PORTRAIT_9_16 })
  @IsEnum(AspectRatioDto)
  @IsOptional()
  aspectRatio?: AspectRatioDto;

  @ApiPropertyOptional({
    description: 'Video stili (CINEMATIC, DOCUMENTARY, vb.)',
    default: 'CINEMATIC',
  })
  @IsString()
  @IsOptional()
  @MaxLength(50)
  videoStyle?: string;

  @ApiPropertyOptional({ description: 'Sinematik stil referansı (örn: Wes Anderson, Matrix)' })
  @IsString()
  @IsOptional()
  @MaxLength(200)
  cinematicReference?: string;

  @ApiPropertyOptional({ description: 'Hedef video süresi (saniye)', default: 60 })
  @IsInt()
  @IsOptional()
  @Min(15)
  @Max(180)
  targetDuration?: number;
}

export class CreateFromDocumentDto {
  @ApiPropertyOptional({
    description: 'Proje başlığı (boş bırakılırsa belgeden otomatik üretilir)',
  })
  @IsString()
  @IsOptional()
  @MaxLength(200)
  title?: string;

  @ApiPropertyOptional({
    description: 'Hedef video dili (ISO 639-1)',
    default: 'tr',
  })
  @IsString()
  @IsOptional()
  language?: string;

  @ApiPropertyOptional({ enum: AspectRatioDto, default: AspectRatioDto.PORTRAIT_9_16 })
  @IsEnum(AspectRatioDto)
  @IsOptional()
  aspectRatio?: AspectRatioDto;

  @ApiPropertyOptional({
    description: 'Video stili (CINEMATIC, DOCUMENTARY, vb.)',
    default: 'CINEMATIC',
  })
  @IsString()
  @IsOptional()
  @MaxLength(50)
  videoStyle?: string;

  @ApiPropertyOptional({ description: 'Sinematik stil referansı (örn: Wes Anderson, Matrix)' })
  @IsString()
  @IsOptional()
  @MaxLength(200)
  cinematicReference?: string;

  @ApiPropertyOptional({ description: 'Hedef video süresi (saniye)', default: 60 })
  @IsInt()
  @IsOptional()
  @Min(15)
  @Max(180)
  targetDuration?: number;
}

export class CreateFromExtractedTextDto {
  @ApiProperty({ description: 'Çıkarılan metin' })
  @IsString()
  @IsNotEmpty()
  text: string;

  @ApiProperty({ description: 'Seçilen video konusu' })
  @IsString()
  @IsNotEmpty()
  topic: string;

  @ApiPropertyOptional({ description: 'Orijinal dosya adı' })
  @IsString()
  @IsOptional()
  originalFilename?: string;

  @ApiPropertyOptional({ description: 'Video dili (ISO 639-1)', default: 'tr' })
  @IsString()
  @IsOptional()
  @MaxLength(5)
  language?: string;

  @ApiPropertyOptional({
    description: 'En-boy oranı (PORTRAIT_9_16, LANDSCAPE_16_9, SQUARE_1_1)',
    default: 'PORTRAIT_9_16',
  })
  @IsString()
  @IsOptional()
  @MaxLength(20)
  aspectRatio?: string;

  @ApiPropertyOptional({
    description: 'Video stili (CINEMATIC, DOCUMENTARY, vb.)',
    default: 'CINEMATIC',
  })
  @IsString()
  @IsOptional()
  @MaxLength(50)
  videoStyle?: string;

  @ApiPropertyOptional({ description: 'Sinematik stil referansı (örn: Wes Anderson, Matrix)' })
  @IsString()
  @IsOptional()
  @MaxLength(200)
  cinematicReference?: string;

  @ApiPropertyOptional({ description: 'Hedef video süresi (saniye)', default: 60 })
  @IsInt()
  @IsOptional()
  @Min(15)
  @Max(180)
  targetDuration?: number;
}
