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

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

  @ApiProperty({ required: false })
  @IsString()
  @IsOptional()
  cover?: string;

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

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

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

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

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

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

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

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

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

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

  @ApiProperty({ required: false, default: 0 })
  @IsNumber()
  @IsOptional()
  order?: number;

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

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

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

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

  @ApiProperty({ required: false })
  @IsString()
  @IsOptional()
  sourceId?: number;
}
export class GetMenuDto {
  @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 QueryMenuDto extends GetMenuDto {
  @ApiProperty({ required: false })
  @Allow()
  parentId?: number;
}

export class UpdateMenuDto extends PartialType(CreateMenuDto) {
  @Exclude()
  user?: User;
}

export class UploadCoverDto {
  @ApiProperty({ type: 'string', format: 'binary', required: true })
  file: Express.Multer.File;
}
