from __future__ import annotations from typing import Any from app.brand.errors import BrandValidationError _PLATFORM_FIELDS: dict[str, frozenset[str]] = { "facebook": frozenset({"caption_style", "hashtags", "cta"}), "instagram": frozenset({"caption_style", "hashtags", "cta", "first_comment"}), "tiktok": frozenset({"caption_style", "hashtags", "cta"}), "x": frozenset({"caption_style", "hashtags", "cta"}), "youtube": frozenset({"title_pattern", "description", "tags", "cta"}), "linkedin": frozenset({"post_style", "hashtags", "cta"}), "telegram": frozenset({"caption_style", "cta"}), "whatsapp": frozenset({"caption_style", "cta"}), } def validate_platform_settings(provider: str, settings: dict[str, Any]) -> None: unsupported = set(settings) - _PLATFORM_FIELDS.get(provider, frozenset()) if unsupported: raise BrandValidationError( f"Unsupported {provider} brand defaults: {', '.join(sorted(unsupported))}." ) for key, value in settings.items(): if isinstance(value, str) and len(value) > 4000: raise BrandValidationError(f"{provider}.{key} exceeds the supported length.") if isinstance(value, list) and len(value) > 100: raise BrandValidationError(f"{provider}.{key} contains too many values.")