/**
 * 表单模板 DTOs
 * 完全符合 API 文档规范
 */

import {
  IsString,
  IsObject,
  IsOptional,
  IsBoolean,
  IsInt,
  Min,
} from 'class-validator';
import { Type } from 'class-transformer';
// import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';  // TODO: Install @nestjs/swagger

// ============================================
// 创建表单模板
// ============================================

export class CreateFormTemplateDto {
  // @ApiProperty({
    // description: '模板名称（多语言）',
    // example: { 'zh-CN': '报销申请模板', 'en-US': 'Expense Report Template' },
  // })
  @IsObject()
  nameI18n: Record<string, string>;

  // @ApiPropertyOptional({
    // description: '模板描述（多语言）',
  // })
  @IsOptional()
  @IsObject()
  descriptionI18n?: Record<string, string>;

  // @ApiProperty({
    // description: '分类',
    // example: 'finance',
  // })
  @IsString()
  category: string;

  // @ApiPropertyOptional({
    // description: '图标',
    // example: 'Receipt',
  // })
  @IsOptional()
  @IsString()
  icon?: string;

  // @ApiPropertyOptional({
    // description: '主题色',
    // example: '#3b82f6',
  // })
  @IsOptional()
  @IsString()
  color?: string;

  // @ApiProperty({
    // description: '模板内容（完整的表单定义）',
    // example: {
      // key: 'expense-form',
      // name: '报销申请',
      // schema: {},
    // },
  // })
  @IsObject()
  template: any;

  // @ApiProperty({
    // description: '是否为系统内置模板',
    // default: false,
  // })
  @IsBoolean()
  isBuiltin: boolean;

  // @ApiProperty({
    // description: '是否公开（所有用户可见）',
    // default: true,
  // })
  @IsBoolean()
  isPublic: boolean;
}

// ============================================
// 更新表单模板
// ============================================

export class UpdateFormTemplateDto {
  // @ApiPropertyOptional({
    // description: '模板名称（多语言）',
  // })
  @IsOptional()
  @IsObject()
  nameI18n?: Record<string, string>;

  // @ApiPropertyOptional({
    // description: '模板描述（多语言）',
  // })
  @IsOptional()
  @IsObject()
  descriptionI18n?: Record<string, string>;

  // @ApiPropertyOptional({
    // description: '分类',
  // })
  @IsOptional()
  @IsString()
  category?: string;

  // @ApiPropertyOptional({
    // description: '图标',
  // })
  @IsOptional()
  @IsString()
  icon?: string;

  // @ApiPropertyOptional({
    // description: '主题色',
  // })
  @IsOptional()
  @IsString()
  color?: string;

  // @ApiPropertyOptional({
    // description: '模板内容',
  // })
  @IsOptional()
  @IsObject()
  template?: any;

  // @ApiPropertyOptional({
    // description: '是否公开',
  // })
  @IsOptional()
  @IsBoolean()
  isPublic?: boolean;
}

// ============================================
// 查询表单模板
// ============================================

export class QueryFormTemplatesDto {
  // @ApiPropertyOptional({
    // description: '分类',
  // })
  @IsOptional()
  @IsString()
  category?: string;

  // @ApiPropertyOptional({
    // description: '是否公开',
  // })
  @IsOptional()
  @Type(() => Boolean)
  @IsBoolean()
  isPublic?: boolean;

  // @ApiPropertyOptional({
    // description: '搜索关键词',
  // })
  @IsOptional()
  @IsString()
  search?: string;

  // @ApiPropertyOptional({ description: '页码', default: 1, minimum: 1 })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  page?: number;

  // @ApiPropertyOptional({
    // description: '每页数量',
    // default: 20,
    // minimum: 1,
    // maximum: 100,
  // })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  limit?: number;
}

// ============================================
// 从模板创建表单
// ============================================

export class CreateFormFromTemplateDto {
  // @ApiProperty({
    // description: '新表单的 slug',
    // example: 'my-expense-form',
  // })
  @IsString()
  slug: string;

  // @ApiProperty({
    // description: '新表单的名称（多语言）',
    // example: { 'zh-CN': '我的报销申请', 'en-US': 'My Expense Report' },
  // })
  @IsObject()
  name: Record<string, string>;

  // @ApiPropertyOptional({
    // description: '新表单的分类（不指定则使用模板的分类）',
  // })
  @IsOptional()
  @IsString()
  category?: string;
}

