"""{{ display_name }} MCP server — generated by mcpify. Do not hand-edit.

Validates arguments against the input schema, injects the active auth
strategy's credentials, executes the live HTTP request, and validates the
response against the output schema before returning it — PRD §1.5's
`call` pipeline (architecture.md's 4-step `call` pipeline), protecting the
calling agent from upstream API drift.
"""

from __future__ import annotations

from typing import Any

from ..auth.auth_manager import AuthManager
from ..auth.request_credentials import RequestCredentials
from ..core.config import Config
from ..data.store import EndpointRecord
from ..services.api_client import ApiClient
from ..validation.validator import validate_input, validate_output


async def call_operation(
    endpoint: EndpointRecord,
    config: Config,
    auth_manager: AuthManager,
    operation_id: str,
    args: dict[str, Any],
    request_override: RequestCredentials | None = None,
) -> Any:
    validate_input(config.api_version, operation_id, args)

    client = ApiClient(config)
    response = await client.execute(endpoint, args, auth_manager, request_override)

    validate_output(config.api_version, operation_id, response)
    return response
