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

export enum Theme {
  LIGHT = 'light',
  DARK = 'dark',
  SYSTEM = 'system',
}

export enum Language {
  DE = 'de',
  EN = 'en',
}

export class WidgetConfig {
  @ApiPropertyOptional({
    description: 'Widget identifier',
    example: 'stats-overview',
  })
  @IsString()
  id: string;

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

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

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

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

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

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

export class NotificationPreferences {
  @ApiPropertyOptional({
    description: 'Enable email notifications',
    example: true,
  })
  @IsOptional()
  email?: boolean;

  @ApiPropertyOptional({
    description: 'Enable push notifications',
    example: true,
  })
  @IsOptional()
  push?: boolean;

  @ApiPropertyOptional({
    description: 'Enable absence request notifications',
    example: true,
  })
  @IsOptional()
  absenceRequests?: boolean;

  @ApiPropertyOptional({
    description: 'Enable time tracking reminders',
    example: true,
  })
  @IsOptional()
  timeReminders?: boolean;

  @ApiPropertyOptional({
    description: 'Enable system announcements',
    example: true,
  })
  @IsOptional()
  systemAnnouncements?: boolean;
}

export class UpdatePreferencesDto {
  @ApiPropertyOptional({
    description: 'UI theme preference',
    enum: Theme,
    example: Theme.SYSTEM,
  })
  @IsOptional()
  @IsEnum(Theme)
  theme?: Theme;

  @ApiPropertyOptional({
    description: 'Language preference',
    enum: Language,
    example: Language.DE,
  })
  @IsOptional()
  @IsEnum(Language)
  language?: Language;

  @ApiPropertyOptional({
    description: 'Dashboard widget layout configuration',
    type: [WidgetConfig],
  })
  @IsOptional()
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => WidgetConfig)
  dashboardLayout?: WidgetConfig[];

  @ApiPropertyOptional({
    description: 'Notification preferences',
    type: NotificationPreferences,
  })
  @IsOptional()
  @ValidateNested()
  @Type(() => NotificationPreferences)
  notifications?: NotificationPreferences;
}
