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

  @ApiProperty({ required: true })
  @IsString()
  content: string;

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

  @ApiProperty({ required: true })
  @IsNumber()
  categoryId: number;

  @ApiProperty({ required: false, default: true })
  @IsBoolean()
  @IsOptional()
  isShow?: boolean;

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

  @ApiProperty({ required: false })
  @IsArray()
  @IsOptional()
  translations?: CreateArticleTranslations[];
}
export class CreateArticleTranslations {
  @ApiProperty({ required: false })
  @IsString()
  locale: string;

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

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

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

  @ApiProperty({ required: true })
  @IsString()
  content: string;

  @ApiProperty({ required: false })
  @IsNumber()
  @IsOptional()
  articleId?: number;
}

export class GetArticleDto {
  @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 QueryArticleDto extends GetArticleDto {}

export class UpdateArticleDto extends CreateArticleDto {
}
