import { IsOptional, IsString, IsBoolean, IsIn, Matches, IsUrl, MinLength, MaxLength, ValidateIf } from 'class-validator';

export class UpdateSettingsDto {
    @IsOptional()
    @IsString()
    @MinLength(1, { message: 'School name cannot be empty' })
    schoolName?: string;

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

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

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

    @IsOptional()
    @IsUrl()
    schoolWebsite?: string;

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

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

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

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

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

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

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

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

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

    @IsOptional()
    @IsIn(['light', 'dark'])
    theme?: 'light' | 'dark';

    @IsOptional()
    @Matches(/^#[0-9A-Fa-f]{6}$/, { message: 'primaryColor must be a valid hex color' })
    primaryColor?: string;

    @IsOptional()
    @Matches(/^#[0-9A-Fa-f]{6}$/, { message: 'secondaryColor must be a valid hex color' })
    secondaryColor?: string;

    @IsOptional()
    @Matches(/^#[0-9A-Fa-f]{6}$/, { message: 'lightPrimaryColor must be a valid hex color' })
    lightPrimaryColor?: string;

    @IsOptional()
    @Matches(/^#[0-9A-Fa-f]{6}$/, { message: 'lightSecondaryColor must be a valid hex color' })
    lightSecondaryColor?: string;

    @IsOptional()
    @Matches(/^#[0-9A-Fa-f]{6}$/, { message: 'lightPrimaryTextColor must be a valid hex color' })
    lightPrimaryTextColor?: string;

    @IsOptional()
    @Matches(/^#[0-9A-Fa-f]{6}$/, { message: 'lightSecondaryTextColor must be a valid hex color' })
    lightSecondaryTextColor?: string;

    @IsOptional()
    @Matches(/^#[0-9A-Fa-f]{6}$/, { message: 'darkPrimaryColor must be a valid hex color' })
    darkPrimaryColor?: string;

    @IsOptional()
    @Matches(/^#[0-9A-Fa-f]{6}$/, { message: 'darkSecondaryColor must be a valid hex color' })
    darkSecondaryColor?: string;

    @IsOptional()
    @Matches(/^#[0-9A-Fa-f]{6}$/, { message: 'darkPrimaryTextColor must be a valid hex color' })
    darkPrimaryTextColor?: string;

    @IsOptional()
    @Matches(/^#[0-9A-Fa-f]{6}$/, { message: 'darkSecondaryTextColor must be a valid hex color' })
    darkSecondaryTextColor?: string;

    @IsOptional()
    @ValidateIf((o) => o.primaryTextColor !== null)
    @Matches(/^#[0-9A-Fa-f]{6}$/, { message: 'primaryTextColor must be a valid hex color' })
    primaryTextColor?: string | null;

    @IsOptional()
    @ValidateIf((o) => o.secondaryTextColor !== null)
    @Matches(/^#[0-9A-Fa-f]{6}$/, { message: 'secondaryTextColor must be a valid hex color' })
    secondaryTextColor?: string | null;

    @IsOptional()
    @Matches(/^\+?[1-9]\d{1,14}$/, { message: 'Invalid WhatsApp number format' })
    whatsappNumber?: string;

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

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

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

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

    @IsOptional()
    @IsString()
    @MaxLength(2000, { message: 'Invoice terms must not exceed 2000 characters' })
    invoiceTerms?: string;

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