import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsString, IsOptional, IsNumber, IsObject, IsArray, ValidateNested } from 'class-validator';
import { Type } from 'class-transformer';

export class WidgetLayoutDto {
  @ApiProperty({
    description: 'Unique widget identifier',
    example: 'stats-overview',
  })
  @IsString()
  id: string;

  @ApiProperty({
    description: 'Widget type',
    example: 'statistics',
  })
  @IsString()
  type: string;

  @ApiPropertyOptional({
    description: 'Grid position X',
    example: 0,
  })
  @IsOptional()
  @IsNumber()
  x?: number;

  @ApiPropertyOptional({
    description: 'Grid position Y',
    example: 0,
  })
  @IsOptional()
  @IsNumber()
  y?: number;

  @ApiPropertyOptional({
    description: 'Widget width in grid units',
    example: 2,
  })
  @IsOptional()
  @IsNumber()
  w?: number;

  @ApiPropertyOptional({
    description: 'Widget height in grid units',
    example: 2,
  })
  @IsOptional()
  @IsNumber()
  h?: number;

  @ApiPropertyOptional({
    description: 'Widget-specific settings',
  })
  @IsOptional()
  @IsObject()
  settings?: Record<string, unknown>;
}

export class UpdateLayoutDto {
  @ApiProperty({
    description: 'Array of widget configurations',
    type: [WidgetLayoutDto],
  })
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => WidgetLayoutDto)
  layout: WidgetLayoutDto[];
}
