"""High-level ECM object API for the ``ecmind_blue_client`` library.

The :func:`ECM` factory function is the main entry point. Depending on the
client type passed in, it returns either a synchronous (``ECMSync``) or an
asynchronous (``ECMAsync``) interface for working with ECM objects such as
folders, registers, and documents.

Example::

    from ecmind_blue_client.pool import SyncPoolClient
    from ecmind_blue_client.ecm import ECM

    client = SyncPoolClient(...)
    ecm = ECM(client)
    with ecm.query() as result:
        ...
"""

from typing import overload

from ecmind_blue_client.ecm._common import (
    DmsObjectFieldValueTypes,
    DmsObjectFieldValueTypesT,
    ECMDocumentDigest,
)
from ecmind_blue_client.ecm._ecm_adm_info_parser import ECMGroup, ECMUser, ECMUserAttributes
from ecmind_blue_client.ecm._ecm_security_roles import ECMSystemRole
from ecmind_blue_client.ecm._ecm_exception import (
    ECMAccessDeniedException,
    ECMException,
    ECMMissingArgumentException,
    ECMNotFoundException,
    ECMWrongStateException,
    raise_for_blue_exception,
)
from ecmind_blue_client.ecm.asynchron import ECMAsync
from ecmind_blue_client.ecm.synchron import ECMSync
from ecmind_blue_client.pool import AsyncPoolClient, SyncPoolClient


@overload
def ECM(client: SyncPoolClient) -> ECMSync: ...


@overload
def ECM(client: AsyncPoolClient) -> ECMAsync: ...


def ECM(client: SyncPoolClient | AsyncPoolClient) -> ECMSync | ECMAsync:
    """Create an ECM interface bound to the given connection pool client.

    The concrete return type is narrowed by the ``@overload`` signatures:
    passing a ``SyncPoolClient`` returns ``ECMSync``, passing an
    ``AsyncPoolClient`` returns ``ECMAsync``.

    Args:
        client: A ``SyncPoolClient`` or ``AsyncPoolClient`` instance.

    Returns:
        ECMSync | ECMAsync: The ECM interface matching the client type.
    """
    if isinstance(client, SyncPoolClient):
        return ECMSync(client)
    return ECMAsync(client)


__all__ = [
    "ECMGroup",
    "ECMSystemRole",
    "ECMUser",
    "ECMUserAttributes",
    "DmsObjectFieldValueTypes",
    "DmsObjectFieldValueTypesT",
    "ECMAccessDeniedException",
    "ECMDocumentDigest",
    "ECMException",
    "ECMMissingArgumentException",
    "ECMNotFoundException",
    "ECMWrongStateException",
    "raise_for_blue_exception",
]
