import {
  IsString,
  IsBoolean,
  IsOptional,
  IsArray,
  ValidateNested,
  IsNumber,
  IsEnum,
  IsNotEmpty,
} from 'class-validator';
import { Type } from 'class-transformer';

/**
 * 列定义
 */
export class ColumnDefinitionDto {
  @IsString()
  @IsNotEmpty()
  key: string;

  @IsString()
  @IsNotEmpty()
  label: string;

  @IsEnum(['standard', 'custom'])
  type: 'standard' | 'custom';

  @IsBoolean()
  visible: boolean;

  @IsNumber()
  @IsOptional()
  width?: number;

  @IsEnum(['left', 'right', 'none'])
  @IsOptional()
  fixed?: 'left' | 'right' | 'none';

  @IsBoolean()
  @IsOptional()
  sortable?: boolean;

  @IsBoolean()
  @IsOptional()
  searchable?: boolean;

  @IsNumber()
  order: number;

  @IsString()
  @IsOptional()
  format?: string;
}

/**
 * 创建列配置 DTO
 */
export class CreateColumnConfigDto {
  @IsString()
  @IsNotEmpty()
  name: string;

  @IsString()
  @IsOptional()
  description?: string;

  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => ColumnDefinitionDto)
  columns: ColumnDefinitionDto[];

  @IsBoolean()
  @IsOptional()
  isDefault?: boolean;

  @IsBoolean()
  @IsOptional()
  isTemplate?: boolean;

  @IsBoolean()
  @IsOptional()
  isPublic?: boolean;
}

/**
 * 更新列配置 DTO
 */
export class UpdateColumnConfigDto {
  @IsString()
  @IsOptional()
  name?: string;

  @IsString()
  @IsOptional()
  description?: string;

  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => ColumnDefinitionDto)
  @IsOptional()
  columns?: ColumnDefinitionDto[];

  @IsBoolean()
  @IsOptional()
  isDefault?: boolean;

  @IsBoolean()
  @IsOptional()
  isTemplate?: boolean;

  @IsBoolean()
  @IsOptional()
  isPublic?: boolean;
}

/**
 * 查询列配置 DTO
 */
export class QueryColumnConfigDto {
  @IsBoolean()
  @IsOptional()
  @Type(() => Boolean)
  includeTemplates?: boolean;

  @IsBoolean()
  @IsOptional()
  @Type(() => Boolean)
  onlyTemplates?: boolean;

  @IsBoolean()
  @IsOptional()
  @Type(() => Boolean)
  onlyPublic?: boolean;
}

/**
 * 复制列配置 DTO
 */
export class CopyColumnConfigDto {
  @IsString()
  @IsNotEmpty()
  name: string;

  @IsString()
  @IsOptional()
  description?: string;
}

