import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsArray, IsBoolean, IsNotEmpty, IsOptional, IsString, ValidateNested } from 'class-validator';
import { Type } from 'class-transformer';

export class CreateBlogTranslationDto {
  @ApiProperty({ description: 'Language code (en, np)', example: 'en' })
  @IsString()
  @IsNotEmpty()
  language: string;

  @ApiProperty({ description: 'Blog title', example: 'My First Blog Post' })
  @IsString()
  @IsNotEmpty()
  title: string;

  @ApiProperty({ description: 'Blog content in markdown', example: '# Introduction\n\nThis is my first blog post.' })
  @IsString()
  @IsNotEmpty()
  content: string;
}

export class CreateBlogDto {
  @ApiPropertyOptional({ description: 'Publication status', example: false, default: false })
  @IsBoolean()
  @IsOptional()
  isPublished?: boolean;

  @ApiPropertyOptional({ description: 'Blog tags', type: [String], example: ['technology', 'programming'] })
  @IsArray()
  @IsString({ each: true })
  @IsOptional()
  tags?: string[];

  @ApiPropertyOptional({ description: 'Featured image URL', example: 'https://example.com/image.jpg' })
  @IsString()
  @IsOptional()
  featuredImageUrl?: string;

  @ApiProperty({
    description: 'Blog translations',
    type: [CreateBlogTranslationDto],
    example: [
      { language: 'en', title: 'My First Blog', content: '# Hello World' },
      { language: 'np', title: 'मेरो पहिलो ब्लग', content: '# नमस्ते संसार' },
    ],
  })
  @ValidateNested({ each: true })
  @Type(() => CreateBlogTranslationDto)
  @IsNotEmpty()
  translations: CreateBlogTranslationDto[];

  @ApiProperty({ description: 'Author names', example: 'John Doe' })
  @IsString({ each: true })
  @IsNotEmpty({ each: true })
  authorNames: string[];

  @ApiProperty({ description: 'Blog slug', example: 'my-first-blog' })
  @IsString()
  @IsNotEmpty()
  slug: string;
}
