"""Service handles for the agentrouter Python SDK.

Each handle wraps one generated proto service. Methods build the
request message, call the SDK's Connect-JSON transport, and return the
typed response message.
"""

from __future__ import annotations

from typing import Any

from google.protobuf import empty_pb2

# Generated bindings: the SDK's ``__init__`` adds ``_gen`` to sys.path so
# these short import paths work whether the SDK is imported from source or
# installed from a wheel.
from tars.aikeys.v1 import aikeys_pb2
from tars.catalog.v1 import catalog_pb2
from tars.clients.v1 import clients_pb2
from tars.identity.v1 import identity_service_pb2
from tars.inference.v1 import inference_pb2
from tars.mcp.v1 import mcp_pb2
from tars.telemetry.v1 import telemetry_pb2
from tars.tenancy.v1 import customer_pb2, project_pb2, tenancy_service_pb2

from ._transport import Transport


# Re-export the BYOK provider enum so callers can write
# ``agentrouter_sdk.aikeys.AIKeyProvider.PROVIDER_OPENAI`` without importing
# from the generated module directly.
AIKeyProvider = aikeys_pb2.Provider


# --- MeService -------------------------------------------------------


class MeHandle:
    SERVICE = "tars.identity.v1.MeService"

    def __init__(self, t: Transport):
        self._t = t

    def login(self, redirect_uri: str, code_challenge: str,
              code_challenge_method: str = "S256", issuer: str = "") -> Any:
        req = identity_service_pb2.LoginRequest(
            issuer=issuer,
            redirect_uri=redirect_uri,
            code_challenge=code_challenge,
            code_challenge_method=code_challenge_method,
        )
        return self._t.unary(self.SERVICE, "Login", req, identity_service_pb2.LoginResponse)

    def logout(self) -> None:
        self._t.unary(self.SERVICE, "Logout", identity_service_pb2.LogoutRequest(), identity_service_pb2.LogoutResponse)

    def get(self) -> Any:
        return self._t.unary(self.SERVICE, "GetMe", identity_service_pb2.GetMeRequest(), identity_service_pb2.GetMeResponse).identity

    def issue_key(self, name: str) -> Any:
        return self._t.unary(self.SERVICE, "IssueMyKey", identity_service_pb2.IssueMyKeyRequest(name=name), identity_service_pb2.IssueMyKeyResponse)

    def list_keys(self) -> list:
        return list(self._t.unary(self.SERVICE, "ListMyKeys", identity_service_pb2.ListMyKeysRequest(), identity_service_pb2.ListMyKeysResponse).keys)

    def revoke_key(self, key_id: str) -> None:
        self._t.unary(self.SERVICE, "RevokeMyKey", identity_service_pb2.RevokeMyKeyRequest(key_id=key_id), identity_service_pb2.RevokeMyKeyResponse)


# --- IdentityService -------------------------------------------------


class IdentityHandle:
    SERVICE = "tars.identity.v1.IdentityService"

    def __init__(self, t: Transport):
        self._t = t

    def resolve_api_key(self, key: str) -> Any:
        """Internal-only on the cluster. Resolves an API key plaintext to its owning Identity."""
        return self._t.unary(self.SERVICE, "ResolveApiKey",
                             identity_service_pb2.ResolveApiKeyRequest(key=key),
                             identity_service_pb2.ResolveApiKeyResponse)


# --- TenancyService --------------------------------------------------


class CustomersHandle:
    SERVICE = "tars.tenancy.v1.TenancyService"

    def __init__(self, t: Transport):
        self._t = t

    def create(self, customer_id: str, display_name: str = "", description: str = "") -> Any:
        req = tenancy_service_pb2.CreateCustomerRequest(
            customer_id=customer_id, display_name=display_name, description=description,
        )
        return self._t.unary(self.SERVICE, "CreateCustomer", req, customer_pb2.Customer)

    def get(self, customer_id: str) -> Any:
        return self._t.unary(self.SERVICE, "GetCustomer",
                             tenancy_service_pb2.GetCustomerRequest(customer_id=customer_id),
                             customer_pb2.Customer)

    def list(self) -> list:
        return list(self._t.unary(self.SERVICE, "ListCustomers",
                                  tenancy_service_pb2.ListCustomersRequest(),
                                  tenancy_service_pb2.ListCustomersResponse).customers)

    def update(self, customer_id: str, display_name: str = "", description: str = "") -> Any:
        req = tenancy_service_pb2.UpdateCustomerRequest(
            customer_id=customer_id, display_name=display_name, description=description,
        )
        return self._t.unary(self.SERVICE, "UpdateCustomer", req, customer_pb2.Customer)

    def archive(self, customer_id: str) -> None:
        self._t.unary(self.SERVICE, "ArchiveCustomer",
                      tenancy_service_pb2.ArchiveCustomerRequest(customer_id=customer_id),
                      empty_pb2.Empty)


# --- ProjectsService -------------------------------------------------


class ProjectsHandle:
    SERVICE = "tars.tenancy.v1.ProjectsService"

    def __init__(self, t: Transport):
        self._t = t

    def create(self, customer_id: str, project_id: str, display_name: str = "", description: str = "") -> Any:
        req = tenancy_service_pb2.CreateProjectRequest(
            customer_id=customer_id, project_id=project_id,
            display_name=display_name, description=description,
        )
        return self._t.unary(self.SERVICE, "CreateProject", req, project_pb2.Project)

    def get(self, customer_id: str, project_id: str) -> Any:
        return self._t.unary(self.SERVICE, "GetProject",
                             tenancy_service_pb2.GetProjectRequest(customer_id=customer_id, project_id=project_id),
                             project_pb2.Project)

    def list(self, customer_id: str) -> list:
        return list(self._t.unary(self.SERVICE, "ListProjects",
                                  tenancy_service_pb2.ListProjectsRequest(customer_id=customer_id),
                                  tenancy_service_pb2.ListProjectsResponse).projects)

    def update(self, customer_id: str, project_id: str, display_name: str = "", description: str = "") -> Any:
        req = tenancy_service_pb2.UpdateProjectRequest(
            customer_id=customer_id, project_id=project_id,
            display_name=display_name, description=description,
        )
        return self._t.unary(self.SERVICE, "UpdateProject", req, project_pb2.Project)

    def archive(self, customer_id: str, project_id: str) -> None:
        self._t.unary(self.SERVICE, "ArchiveProject",
                      tenancy_service_pb2.ArchiveProjectRequest(customer_id=customer_id, project_id=project_id),
                      empty_pb2.Empty)

    def add_member(self, customer_id: str, project_id: str, identity_id: str, role: str) -> Any:
        req = tenancy_service_pb2.AddProjectMemberRequest(
            customer_id=customer_id, project_id=project_id,
            identity_id=identity_id, role=role,
        )
        return self._t.unary(self.SERVICE, "AddProjectMember", req, project_pb2.ProjectMember)

    def list_members(self, customer_id: str, project_id: str) -> list:
        return list(self._t.unary(self.SERVICE, "ListProjectMembers",
                                  tenancy_service_pb2.ListProjectMembersRequest(customer_id=customer_id, project_id=project_id),
                                  tenancy_service_pb2.ListProjectMembersResponse).members)

    def update_member(self, customer_id: str, project_id: str, identity_id: str, role: str) -> Any:
        req = tenancy_service_pb2.UpdateProjectMemberRequest(
            customer_id=customer_id, project_id=project_id,
            identity_id=identity_id, role=role,
        )
        return self._t.unary(self.SERVICE, "UpdateProjectMember", req, project_pb2.ProjectMember)

    def remove_member(self, customer_id: str, project_id: str, identity_id: str) -> None:
        self._t.unary(self.SERVICE, "RemoveProjectMember",
                      tenancy_service_pb2.RemoveProjectMemberRequest(customer_id=customer_id, project_id=project_id, identity_id=identity_id),
                      empty_pb2.Empty)


# --- CatalogService --------------------------------------------------


class CatalogHandle:
    SERVICE = "tars.catalog.v1.CatalogService"

    def __init__(self, t: Transport):
        self._t = t

    def list_providers(self) -> Any:
        return self._t.unary(self.SERVICE, "ListProviders",
                             catalog_pb2.ListProvidersRequest(), catalog_pb2.ListProvidersResponse)

    def get_provider(self, id: str) -> Any:
        return self._t.unary(self.SERVICE, "GetProvider",
                             catalog_pb2.GetProviderRequest(id=id), catalog_pb2.GetProviderResponse).provider

    def list_models(self, provider_id: str = "") -> Any:
        return self._t.unary(self.SERVICE, "ListModels",
                             catalog_pb2.ListModelsRequest(provider_id=provider_id), catalog_pb2.ListModelsResponse)

    def get_model(self, id: str) -> Any:
        return self._t.unary(self.SERVICE, "GetModel",
                             catalog_pb2.GetModelRequest(id=id), catalog_pb2.GetModelResponse).model

    def upsert_provider(self, id: str, display_name: str, base_url: str,
                        supported_auth_schemes: list[str] | None = None) -> Any:
        req = catalog_pb2.UpsertProviderRequest(
            id=id, display_name=display_name, base_url=base_url,
            supported_auth_schemes=supported_auth_schemes or [],
        )
        return self._t.unary(self.SERVICE, "UpsertProvider", req, catalog_pb2.Provider)

    def upsert_model(self, provider_id: str, name: str, *,
                     upstream_model: str = "", input_per_million: str = "",
                     output_per_million: str = "", cache_read_per_million: str = "",
                     max_cost_per_request: str = "", max_context_tokens: int = 0,
                     capabilities: list[str] | None = None) -> Any:
        req = catalog_pb2.UpsertModelRequest(
            provider_id=provider_id, name=name, upstream_model=upstream_model,
            input_per_million=input_per_million, output_per_million=output_per_million,
            cache_read_per_million=cache_read_per_million,
            max_cost_per_request=max_cost_per_request,
            max_context_tokens=max_context_tokens,
            capabilities=capabilities or [],
        )
        return self._t.unary(self.SERVICE, "UpsertModel", req, catalog_pb2.Model)

    def set_provider_credential(self, id: str, credential: str) -> Any:
        return self._t.unary(self.SERVICE, "SetProviderCredential",
                             catalog_pb2.SetProviderCredentialRequest(id=id, credential=credential),
                             catalog_pb2.Provider)

    def delete_provider(self, id: str) -> None:
        self._t.unary(self.SERVICE, "DeleteProvider",
                      catalog_pb2.DeleteProviderRequest(id=id), empty_pb2.Empty)

    def delete_model(self, id: str) -> None:
        self._t.unary(self.SERVICE, "DeleteModel",
                      catalog_pb2.DeleteModelRequest(id=id), empty_pb2.Empty)

    def assign_model_to_project(self, customer_id: str, project_id: str, model_id: str) -> Any:
        return self._t.unary(self.SERVICE, "AssignModelToProject",
                             catalog_pb2.AssignModelToProjectRequest(
                                 customer_id=customer_id, project_id=project_id, model_id=model_id),
                             catalog_pb2.AssignModelToProjectResponse).entry

    def list_project_models(self, customer_id: str, project_id: str) -> list:
        return list(self._t.unary(self.SERVICE, "ListProjectModels",
                                  catalog_pb2.ListProjectModelsRequest(customer_id=customer_id, project_id=project_id),
                                  catalog_pb2.ListProjectModelsResponse).entries)

    def unassign_model_from_project(self, customer_id: str, project_id: str, model_id: str) -> bool:
        resp = self._t.unary(self.SERVICE, "UnassignModelFromProject",
                             catalog_pb2.UnassignModelFromProjectRequest(
                                 customer_id=customer_id, project_id=project_id, model_id=model_id),
                             catalog_pb2.UnassignModelFromProjectResponse)
        return resp.success


# --- AIKeysService ---------------------------------------------------


class AIKeysHandle:
    SERVICE = "tars.aikeys.v1.AiKeysService"

    def __init__(self, t: Transport):
        self._t = t

    def register(self, customer_id: str, project_id: str, provider, name: str, secret: str, user_scope: bool = False) -> Any:
        # user_scope=True registers a per-user key private to the caller that
        # overrides the project key for the caller's own inference traffic;
        # user_scope=False (default) registers a shared project-level key
        # (requires the caller to be the project owner).
        req = aikeys_pb2.RegisterRequest(
            customer_id=customer_id, project_id=project_id,
            provider=provider, name=name, secret=secret, user_scope=user_scope,
        )
        return self._t.unary(self.SERVICE, "Register", req, aikeys_pb2.RegisterResponse).key

    def get(self, customer_id: str, project_id: str, id: str) -> Any:
        return self._t.unary(self.SERVICE, "Get",
                             aikeys_pb2.GetRequest(customer_id=customer_id, project_id=project_id, id=id),
                             aikeys_pb2.GetResponse).key

    def list(self, customer_id: str, project_id: str) -> list:
        return list(self._t.unary(self.SERVICE, "List",
                                  aikeys_pb2.ListRequest(customer_id=customer_id, project_id=project_id),
                                  aikeys_pb2.ListResponse).keys)

    def revoke(self, customer_id: str, project_id: str, id: str) -> None:
        self._t.unary(self.SERVICE, "Revoke",
                      aikeys_pb2.RevokeRequest(customer_id=customer_id, project_id=project_id, id=id),
                      aikeys_pb2.RevokeResponse)

    def fetch(self, id: str) -> Any:
        """Internal-only on the cluster (service-account). Returns the plaintext secret."""
        return self._t.unary(self.SERVICE, "Fetch",
                             aikeys_pb2.FetchRequest(id=id), aikeys_pb2.FetchResponse)


# --- InferenceIngressService -----------------------------------------


class InferenceHandle:
    SERVICE = "tars.inference.v1.InferenceIngressService"

    def __init__(self, t: Transport):
        self._t = t

    def prompt(self, customer_id: str, project_id: str, prompt: str, *,
               model: str = "", key_id: str = "", idempotency_key: str = "") -> Any:
        req = inference_pb2.PromptRequest(
            customer_id=customer_id, project_id=project_id, prompt=prompt,
            model=model, key_id=key_id, idempotency_key=idempotency_key,
        )
        return self._t.unary(self.SERVICE, "Prompt", req, inference_pb2.PromptResponse)


# --- ClientsService --------------------------------------------------


class ClientsHandle:
    SERVICE = "tars.clients.v1.ClientsService"

    def __init__(self, t: Transport):
        self._t = t

    def create(self, customer_id: str, project_id: str, *,
               title: str = "", key_name: str = "") -> Any:
        req = clients_pb2.CreateClientWithKeyRequest(
            customer_id=customer_id, project_id=project_id,
            title=title, key_name=key_name,
        )
        return self._t.unary(self.SERVICE, "CreateClientWithKey", req, clients_pb2.CreateClientWithKeyResponse)

    def list(self, customer_id: str, project_id: str) -> list:
        return list(self._t.unary(self.SERVICE, "ListClients",
                                  clients_pb2.ListClientsRequest(customer_id=customer_id, project_id=project_id),
                                  clients_pb2.ListClientsResponse).clients)

    def get(self, customer_id: str, project_id: str, client_id: str) -> Any:
        return self._t.unary(self.SERVICE, "GetClient",
                             clients_pb2.GetClientRequest(customer_id=customer_id, project_id=project_id, client_id=client_id),
                             clients_pb2.GetClientResponse).client

    def update_title(self, customer_id: str, project_id: str, client_id: str, title: str) -> Any:
        return self._t.unary(self.SERVICE, "UpdateClientTitle",
                             clients_pb2.UpdateClientTitleRequest(
                                 customer_id=customer_id, project_id=project_id,
                                 client_id=client_id, title=title),
                             clients_pb2.UpdateClientTitleResponse).client

    def add_key(self, customer_id: str, project_id: str, client_id: str, key_id: str) -> None:
        self._t.unary(self.SERVICE, "AddKeyToClient",
                      clients_pb2.AddKeyToClientRequest(
                          customer_id=customer_id, project_id=project_id,
                          client_id=client_id, key_id=key_id),
                      clients_pb2.AddKeyToClientResponse)

    def rotate_key(self, customer_id: str, project_id: str, client_id: str, *,
                   key_name: str = "", user_key_address: str = "",
                   old_key_id: str = "", disable_after: str = "",
                   destroy_after: str = "") -> Any:
        req = clients_pb2.RotateKeyInClientRequest(
            customer_id=customer_id, project_id=project_id, client_id=client_id,
            key_name=key_name, user_key_address=user_key_address,
            old_key_id=old_key_id, disable_after=disable_after, destroy_after=destroy_after,
        )
        return self._t.unary(self.SERVICE, "RotateKeyInClient", req, clients_pb2.RotateKeyInClientResponse)

    def disable_key(self, customer_id: str, project_id: str, client_id: str, key_version: str) -> None:
        self._t.unary(self.SERVICE, "DisableKeyVersionInClient",
                      clients_pb2.DisableKeyVersionInClientRequest(
                          customer_id=customer_id, project_id=project_id,
                          client_id=client_id, key_version=key_version),
                      clients_pb2.DisableKeyVersionInClientResponse)

    def enable_key(self, customer_id: str, project_id: str, client_id: str, key_version: str) -> None:
        self._t.unary(self.SERVICE, "EnableKeyVersionInClient",
                      clients_pb2.EnableKeyVersionInClientRequest(
                          customer_id=customer_id, project_id=project_id,
                          client_id=client_id, key_version=key_version),
                      clients_pb2.EnableKeyVersionInClientResponse)

    def destroy_key(self, customer_id: str, project_id: str, client_id: str, key_version: str) -> None:
        self._t.unary(self.SERVICE, "DestroyKeyVersionInClient",
                      clients_pb2.DestroyKeyVersionInClientRequest(
                          customer_id=customer_id, project_id=project_id,
                          client_id=client_id, key_version=key_version),
                      clients_pb2.DestroyKeyVersionInClientResponse)

    def emergency_revoke(self, customer_id: str, project_id: str, client_id: str, key_version: str, *,
                          generate_replacement: bool = False,
                          replacement_key_name: str = "",
                          replacement_user_key_address: str = "") -> Any:
        req = clients_pb2.EmergencyRevokeKeyVersionRequest(
            customer_id=customer_id, project_id=project_id, client_id=client_id,
            key_version=key_version, generate_replacement=generate_replacement,
            replacement_key_name=replacement_key_name,
            replacement_user_key_address=replacement_user_key_address,
        )
        return self._t.unary(self.SERVICE, "EmergencyRevokeKeyVersion", req,
                             clients_pb2.EmergencyRevokeKeyVersionResponse)


# --- TelemetryService ------------------------------------------------


class TelemetryHandle:
    SERVICE = "tars.telemetry.v1.TelemetryService"

    def __init__(self, t: Transport):
        self._t = t

    def create(self, customer_id: str, project_id: str, endpoint: str, *,
               telemetry_type: str = "", protocol: str = "",
               auth_type: str = "", auth_value: str = "",
               api_key_header: str = "", enabled: bool = True) -> Any:
        req = telemetry_pb2.CreateTelemetryConfigRequest(
            customer_id=customer_id, project_id=project_id, endpoint=endpoint,
            telemetry_type=telemetry_type, protocol=protocol,
            auth_type=auth_type, auth_value=auth_value,
            api_key_header=api_key_header, enabled=enabled,
        )
        return self._t.unary(self.SERVICE, "CreateTelemetryConfig", req, telemetry_pb2.TelemetryConfig)

    def list(self, customer_id: str, project_id: str, telemetry_type: str = "", enabled: str = "") -> list:
        req = telemetry_pb2.ListTelemetryConfigsRequest(
            customer_id=customer_id, project_id=project_id,
            telemetry_type=telemetry_type, enabled=enabled,
        )
        return list(self._t.unary(self.SERVICE, "ListTelemetryConfigs", req,
                                  telemetry_pb2.ListTelemetryConfigsResponse).configs)

    def get(self, customer_id: str, project_id: str, config_id: str) -> Any:
        return self._t.unary(self.SERVICE, "GetTelemetryConfig",
                             telemetry_pb2.GetTelemetryConfigRequest(
                                 customer_id=customer_id, project_id=project_id, config_id=config_id),
                             telemetry_pb2.TelemetryConfig)

    def update(self, customer_id: str, project_id: str, config_id: str, *,
               endpoint: str = "", protocol: str = "", auth_type: str = "",
               auth_value: str = "", api_key_header: str = "",
               enabled: str = "", status: str = "") -> Any:
        req = telemetry_pb2.UpdateTelemetryConfigRequest(
            customer_id=customer_id, project_id=project_id, config_id=config_id,
            endpoint=endpoint, protocol=protocol, auth_type=auth_type,
            auth_value=auth_value, api_key_header=api_key_header,
            enabled=enabled, status=status,
        )
        return self._t.unary(self.SERVICE, "UpdateTelemetryConfig", req, telemetry_pb2.TelemetryConfig)

    def delete(self, customer_id: str, project_id: str, config_id: str) -> None:
        self._t.unary(self.SERVICE, "DeleteTelemetryConfig",
                      telemetry_pb2.DeleteTelemetryConfigRequest(
                          customer_id=customer_id, project_id=project_id, config_id=config_id),
                      empty_pb2.Empty)


# --- MCP (Profiles + Catalog) ----------------------------------------


class MCPProfilesHandle:
    SERVICE = "tars.mcp.v1.MCPProfilesService"

    def __init__(self, t: Transport):
        self._t = t

    def create(self, customer_id: str, project_id: str, user_id: str, *,
               name: str, security_policy_type: str,
               description: str = "", security_policy_value: str = "") -> Any:
        req = mcp_pb2.CreateMCPProfileRequest(
            customer_id=customer_id, project_id=project_id, user_id=user_id,
            name=name, description=description,
            security_policy_type=security_policy_type,
            security_policy_value=security_policy_value,
        )
        return self._t.unary(self.SERVICE, "CreateMCPProfile", req, mcp_pb2.MCPProfile)

    def get(self, customer_id: str, project_id: str, user_id: str, profile_id: str) -> Any:
        return self._t.unary(self.SERVICE, "GetMCPProfile",
                             mcp_pb2.GetMCPProfileRequest(
                                 customer_id=customer_id, project_id=project_id,
                                 user_id=user_id, profile_id=profile_id),
                             mcp_pb2.MCPProfile)

    def list(self, customer_id: str, project_id: str, user_id: str) -> Any:
        return self._t.unary(self.SERVICE, "ListMCPProfiles",
                             mcp_pb2.ListMCPProfilesRequest(
                                 customer_id=customer_id, project_id=project_id, user_id=user_id),
                             mcp_pb2.ListMCPProfilesResponse)

    def update(self, customer_id: str, project_id: str, user_id: str, profile_id: str, *,
               name: str = "", description: str = "",
               security_policy_type: str = "", security_policy_value: str = "") -> Any:
        req = mcp_pb2.UpdateMCPProfileRequest(
            customer_id=customer_id, project_id=project_id, user_id=user_id, profile_id=profile_id,
            name=name, description=description,
            security_policy_type=security_policy_type, security_policy_value=security_policy_value,
        )
        return self._t.unary(self.SERVICE, "UpdateMCPProfile", req, mcp_pb2.MCPProfile)

    def delete(self, customer_id: str, project_id: str, user_id: str, profile_id: str) -> None:
        self._t.unary(self.SERVICE, "DeleteMCPProfile",
                      mcp_pb2.DeleteMCPProfileRequest(
                          customer_id=customer_id, project_id=project_id,
                          user_id=user_id, profile_id=profile_id),
                      empty_pb2.Empty)


class MCPCatalogHandle:
    SERVICE = "tars.mcp.v1.MCPCatalogService"

    def __init__(self, t: Transport):
        self._t = t

    def upsert(self, id: str, name: str, url: str, *,
               description: str = "", icon_url: str = "",
               categories: list[str] | None = None, note: str = "",
               authentication: str = "", requires_auth: bool = False,
               requires_profile: bool = False) -> Any:
        req = mcp_pb2.UpsertCatalogServerRequest(
            id=id, name=name, url=url, description=description,
            icon_url=icon_url,
            categories=categories or [], note=note,
            authentication=authentication,
            requires_auth=requires_auth, requires_profile=requires_profile,
        )
        return self._t.unary(self.SERVICE, "UpsertCatalogServer", req, mcp_pb2.MCPCatalogServer)

    def get(self, id: str) -> Any:
        return self._t.unary(self.SERVICE, "GetCatalogServer",
                             mcp_pb2.GetCatalogServerRequest(id=id),
                             mcp_pb2.MCPCatalogServer)

    def list(self, include_disabled: bool = False) -> Any:
        return self._t.unary(self.SERVICE, "ListCatalogServers",
                             mcp_pb2.ListCatalogServersRequest(include_disabled=include_disabled),
                             mcp_pb2.ListCatalogServersResponse)

    def set_enabled(self, id: str, enabled: bool) -> Any:
        return self._t.unary(self.SERVICE, "SetCatalogServerEnabled",
                             mcp_pb2.SetCatalogServerEnabledRequest(id=id, enabled=enabled),
                             mcp_pb2.MCPCatalogServer)

    def delete(self, id: str) -> None:
        self._t.unary(self.SERVICE, "DeleteCatalogServer",
                      mcp_pb2.DeleteCatalogServerRequest(id=id), empty_pb2.Empty)


class MCPHandle:
    """Aggregates the MCP profile + catalog handles."""

    def __init__(self, profiles: MCPProfilesHandle, catalog: MCPCatalogHandle):
        self.profiles = profiles
        self.catalog = catalog
