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

class WidgetColorsDto {
  @ApiPropertyOptional({ example: '#3B82F6' })
  @IsOptional()
  @IsString()
  primary?: string;

  @ApiPropertyOptional({ example: '#1E40AF' })
  @IsOptional()
  @IsString()
  primaryHover?: string;

  @ApiPropertyOptional({ example: '#FFFFFF' })
  @IsOptional()
  @IsString()
  background?: string;

  @ApiPropertyOptional({ example: '#1F2937' })
  @IsOptional()
  @IsString()
  text?: string;

  @ApiPropertyOptional({ example: '#6B7280' })
  @IsOptional()
  @IsString()
  textSecondary?: string;
}

class WidgetFieldsDto {
  @ApiPropertyOptional({ default: true })
  @IsOptional()
  @IsBoolean()
  showEmail?: boolean;

  @ApiPropertyOptional({ default: false })
  @IsOptional()
  @IsBoolean()
  requireEmail?: boolean;

  @ApiPropertyOptional({ default: true })
  @IsOptional()
  @IsBoolean()
  showComment?: boolean;

  @ApiPropertyOptional({ default: false })
  @IsOptional()
  @IsBoolean()
  showGroupEvents?: boolean;

  @ApiPropertyOptional({ default: true })
  @IsOptional()
  @IsBoolean()
  showWeekSchedule?: boolean;
}

export class UpdateWidgetSettingsDto {
  @ApiPropertyOptional({ example: 'Запись на тренировку' })
  @IsOptional()
  @IsString()
  title?: string;

  @ApiPropertyOptional({ example: 'https://example.com/logo.png' })
  @IsOptional()
  @IsUrl()
  logoUrl?: string;

  @ApiPropertyOptional()
  @IsOptional()
  @ValidateNested()
  @Type(() => WidgetColorsDto)
  colors?: WidgetColorsDto;

  @ApiPropertyOptional()
  @IsOptional()
  @ValidateNested()
  @Type(() => WidgetFieldsDto)
  fields?: WidgetFieldsDto;

  @ApiPropertyOptional({ description: 'Redirect URL after successful booking' })
  @IsOptional()
  @IsUrl()
  successRedirectUrl?: string;

  @ApiPropertyOptional({ description: 'Custom CSS for advanced styling' })
  @IsOptional()
  @IsString()
  customCss?: string;

  @ApiPropertyOptional({ default: true })
  @IsOptional()
  @IsBoolean()
  isEnabled?: boolean;
}
