from dataclasses import dataclass

from fluidattacks_zoho_sdk._http_client import ClientFactory, HttpJsonClient
from fluidattacks_zoho_sdk.auth import Credentials
from fluidattacks_zoho_sdk.bulk_export import BulkApiFactory
from fluidattacks_zoho_sdk.bulk_export.core import BulkClient
from fluidattacks_zoho_sdk.ids import OrgId

from . import _client
from .core import AgentObj, ContactObj, DeskClient, UserObj


def _bulk_client(creds: Credentials, org_id: OrgId) -> BulkClient:
    return BulkApiFactory.new(creds, org_id)


def _from_client(client: HttpJsonClient, creds: Credentials, org_id: OrgId) -> DeskClient:
    bulk_client = _bulk_client(creds, org_id)
    return DeskClient(
        lambda t, li: _client.get_contacts(client, t, li),
        lambda t, li: _client.get_tickets(client, t, li),
        lambda t: _client.get_teams(client, t),
        lambda t: _client.fetch_bulk_export_agents(bulk_client, t),
    )


@dataclass(frozen=True)
class DeskAgentClientFactory:
    @staticmethod
    def new(creds: Credentials, org_id: OrgId) -> DeskClient:
        http_client = ClientFactory.new(creds, org_id)
        return _from_client(http_client, creds, org_id)


__all__ = [
    "AgentObj",
    "ContactObj",
    "DeskAgentClient",
    "DeskAgentClientFactory",
    "UserObj",
]
