"""Type definitions for JSON import data structures."""
from __future__ import annotations
import logging
from typing import Literal, TypedDict
from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from onegov.pas.log import OutputHandler
[docs]
class EmailData(TypedDict):
[docs]
    thirdPartyId: str | None 
 
[docs]
class AddressData(TypedDict):
[docs]
    organisationNameAddOn1: str 
[docs]
    organisationNameAddOn2: str 
[docs]
    postOfficeBox: str 
[docs]
    thirdPartyId: str | None 
 
[docs]
class PhoneNumberData(TypedDict):
[docs]
    otherPhoneCategory: str | None 
[docs]
    phoneCategoryText: str 
[docs]
    thirdPartyId: str | None 
 
[docs]
class UrlData(TypedDict):
[docs]
    thirdPartyId: str | None 
 
[docs]
class OrganizationData(TypedDict):
[docs]
    organizationTypeTitle: (
        Literal['Kommission', 'Fraktion', 'Kantonsrat', 'Sonstige'] | None
    ) 
[docs]
    thirdPartyId: str | None 
 
[docs]
class OrganizationDataWithinMembership(TypedDict):
[docs]
    organizationTypeTitle: (
        Literal['Kommission', 'Fraktion', 'Kantonsrat', 'Sonstige'] | None
    ) 
[docs]
    primaryEmail: EmailData | None 
[docs]
    thirdPartyId: str | None 
[docs]
    primaryAddress: AddressData | None 
[docs]
    primaryPhoneNumber: PhoneNumberData | None 
[docs]
    primaryUrl: UrlData | None 
 
[docs]
class PersonData(TypedDict):
[docs]
    personTypeTitle: str | None 
[docs]
    primaryEmail: EmailData | None 
 
[docs]
class MembershipData(TypedDict):
[docs]
    emailReceptionType: str 
[docs]
    organization: OrganizationDataWithinMembership 
[docs]
    primaryAddress: AddressData | None 
[docs]
    primaryEmail: EmailData | None 
[docs]
    primaryPhoneNumber: PhoneNumberData | None 
[docs]
    primaryUrl: UrlData | None 
[docs]
    email: EmailData | None 
[docs]
    phoneNumber: PhoneNumberData | None 
[docs]
    address: AddressData | None 
[docs]
    urlField: UrlData | None 
[docs]
    start: str | bool | None 
[docs]
    thirdPartyId: str | None 
 
[docs]
class OutputLogHandler(logging.Handler):
    """Logging handler that forwards messages to an OutputHandler."""
    def __init__(self, output_handler: OutputHandler) -> None:
        super().__init__()
[docs]
        self.output_handler = output_handler 
[docs]
    def emit(self, record: logging.LogRecord) -> None:
        """Format and send log record to the output handler."""
        try:
            message = self.format(record)
            self.output_handler.info(message)
        except Exception:  # nosec B110
            # Avoid recursion in case of logging errors
            pass