import { ApiProperty, ApiBody, PartialType } from '@nestjs/swagger';
import { Exclude } from 'class-transformer';
import {
  Allow,
  IsArray,
  IsBoolean,
  IsNotEmpty,
  IsNumber,
  IsOptional,
  IsString,
  Length,
} from 'class-validator';

export class CreateCategoryDto {
  @ApiProperty({ required: true })
  @IsNumber()
  userId: number;

  @ApiProperty()
  @IsString()
  @IsNotEmpty({ message: '标题不能为空' })
  @Length(1, 200, {
    message: `用户名长度必须大于$constraint1到$constraint2之间，当前传递的值是$value`,
  })
  title: string;

  @ApiProperty({ required: false })
  @IsBoolean()
  @IsOptional()
  enable?: boolean;

  @ApiProperty({ nullable: true, required: false })
  @IsNumber()
  @IsOptional()
  parentId?: number;

  @ApiProperty({ nullable: true, required: false })
  @IsString()
  @IsOptional()
  remark?: string;

  @ApiProperty({ required: false })
  @IsArray()
  @IsOptional()
  translations?: CreateCategoryTranslations[];
}

export class GetCategoryDto {
  @ApiProperty({ required: false })
  @Allow()
  pageSize?: number;

  @ApiProperty({ required: false })
  @Allow()
  pageNo?: number;

  @ApiProperty({ required: false })
  @Allow()
  title?: string;

  @ApiProperty({ required: false })
  @Allow()
  enable?: boolean;
}
export class CreateCategoryTranslations {
  @ApiProperty({ required: false })
  @IsString()
  locale: string;

  @ApiProperty({ required: false })
  @IsString()
  title: string;

  @ApiProperty({ required: false })
  @IsString()
  remark: string;

  @ApiProperty({ required: false })
  @IsString()
  @IsOptional()
  sourceId?: number;
}

export class GetAllCategoryDto {
  @ApiProperty({ required: false })
  @IsOptional()
  enable?: boolean;
}

export class UpdateCategoryDto extends PartialType(CreateCategoryDto) {}
