"""Validation helpers for future ISTAT XML generation."""

from __future__ import annotations

from istat.xml_export.exceptions import XmlPayloadValidationError
from istat.xml_export.services.lookup_service import IstatLookupService


def validate_country_mapping(country_code: str | None) -> dict[str, str]:
    """Validate and return the ISTAT XML country mapping for an ISO-2 code."""
    country = IstatLookupService.get_country(country_code)
    if country is None:
        normalized = (country_code or "").strip().upper()
        raise XmlPayloadValidationError(f"Missing ISTAT country mapping for '{normalized}'")
    return country


def validate_province_mapping(province_sigla: str | None) -> dict[str, str]:
    """Validate and return the ISTAT XML province mapping for a province sigla."""
    province = IstatLookupService.get_province(province_sigla)
    if province is None:
        normalized = (province_sigla or "").strip().upper()
        raise XmlPayloadValidationError(f"Missing ISTAT province mapping for '{normalized}'")
    return province
