import {
  IsString,
  IsOptional,
  IsNumber,
  IsObject,
  MinLength,
  MaxLength,
  Min,
  Max,
} from "class-validator";

/**
 * DTO for creating a widget configuration in a layout
 */
export class CreateWidgetConfigDto {
  @IsString({ message: "widgetType must be a string" })
  @MinLength(1, { message: "widgetType must not be empty" })
  widgetType!: string;

  @IsNumber({}, { message: "x must be a number" })
  @Min(0, { message: "x must be at least 0" })
  x!: number;

  @IsNumber({}, { message: "y must be a number" })
  @Min(0, { message: "y must be at least 0" })
  y!: number;

  @IsNumber({}, { message: "w must be a number" })
  @Min(1, { message: "w must be at least 1" })
  @Max(12, { message: "w must not exceed 12" })
  w!: number;

  @IsNumber({}, { message: "h must be a number" })
  @Min(1, { message: "h must be at least 1" })
  @Max(12, { message: "h must not exceed 12" })
  h!: number;

  @IsOptional()
  @IsString({ message: "title must be a string" })
  @MaxLength(100, { message: "title must not exceed 100 characters" })
  title?: string;

  @IsOptional()
  @IsObject({ message: "config must be an object" })
  config?: Record<string, unknown>;
}
