"""Hosting provider protocols — deployment plane and routing plane."""
from __future__ import annotations

from typing import Protocol

from src.domain.hosting.types import DeployArtifact, DeployJobContext, DeploymentOutcome, DeploymentTarget, RoutingDescriptor


class DeploymentPlaneProvider(Protocol):
    """Provider that manages app deployments (CF Pages, external origin, etc.)."""

    async def ensure_project_environment(self, ctx: DeployJobContext) -> DeploymentOutcome:
        """Idempotent: create/verify the hosting project on the provider side."""

    async def get_deployment_status(self, ctx: DeployJobContext) -> DeploymentOutcome:
        """Poll or inspect the provider for the deployment at ``ctx.git_sha``."""


class RoutingPlaneProvider(Protocol):
    """Provider that manages hostname → target routing (W4P KV + proxy Workers)."""

    async def ensure_dispatch_namespace(self, environment: str) -> dict:
        """Idempotent: ensure the W4P dispatch namespace for this environment exists."""

    async def upsert_route(self, hostname: str, descriptor: RoutingDescriptor, environment: str) -> None:
        """Write (or update) the routing record for ``hostname``."""

    async def delete_route(self, hostname: str, project_ref: str, environment: str) -> None:
        """Remove routing records for ``hostname``."""

    async def activate_route(
        self,
        ctx: DeployJobContext,
        target_url: str,
        deployment_target_id: str | None,
        active_deployment_id: str | None,
    ) -> DeploymentOutcome:
        """High-level helper: upload proxy Worker + write KV in one call."""


# Backwards-compat alias (old code imported HostingProvider)
HostingProvider = DeploymentPlaneProvider
