import { IsNotEmpty, IsString, IsOptional, IsArray, ValidateNested, ArrayMinSize } from 'class-validator';
import { Type } from 'class-transformer';
import { validationMessages } from '../../../messages/validation-messages';
import { ApiProperty } from '@nestjs/swagger';

export class TranslationDto {
    @ApiProperty({ example: 'en', required: true, type: 'string' })
    @IsNotEmpty({ message: validationMessages.categories.language_code_required })
    @IsString()
    language_code: string;

    @ApiProperty({ example: 'English Category', required: true, type: 'string' })
    title: string;

    @ApiProperty({ example: 'Category description', required: false, type: 'string' })
    @IsOptional()
    @IsString()
    description?: string;

    @ApiProperty({ example: 'English Category', required: false, type: 'string' })
    @IsOptional()
    display_title?: string;
}

export class CreateDto {
    @ApiProperty({ example: 'LINK', required: false, type: 'string' })
    @IsOptional()
    @IsString()
    image?: string;

    @ApiProperty({ example: 'ABC,XYZ,PQR', required: false, type: 'string' })
    @IsOptional()
    @IsString()
    tags?: string;

    @ApiProperty({
        example: [
            {
                language_code: 'en',
                description: 'ssdsd',
                title: 'English Category'
            },
            {
                language_code: 'cn',
                description: 'ssdsd',
                title: 'English Category'
            }
        ],
        required: true,
        type: [TranslationDto]
    })
    @IsArray()
    @ArrayMinSize(1, { message: validationMessages.categories.translations_required })
    @ValidateNested({ each: true })
    @Type(() => TranslationDto)
    translations: TranslationDto[];
}
