"""External origin adapter — no-op deployment for wordpress_theme, shopify_theme, etc.

These project types are hosted externally (AWS, private servers, Shopify partner accounts).
The adapter records metadata and routing descriptors but performs no automated deployment.
Operators must configure the external origin URL manually and update the routing KV entry.
"""
from __future__ import annotations

import structlog

from src.config import Settings, get_settings
from src.domain.hosting.types import DeployArtifact, DeployJobContext, DeploymentOutcome, DeploymentTarget

logger = structlog.get_logger()


class ExternalOriginProvider:
    """No-op deployment plane for externally-hosted project types."""

    def __init__(self, settings: Settings | None = None):
        self._s = settings or get_settings()

    async def ensure_project_environment(self, ctx: DeployJobContext) -> DeploymentOutcome:
        logger.info(
            "external_origin_noop_ensure",
            project_ref=ctx.project_ref,
            environment=ctx.environment,
        )
        return DeploymentOutcome(
            ok=True,
            last_completed_step="ensure_project_environment",
            activation_status="external_manual_required",
            message=(
                "External origin project: no automated deployment. "
                "Configure the origin URL manually and update W4P routing."
            ),
            metadata={"adapter": "external_origin"},
        )

    async def deploy_artifact(
        self,
        ctx: DeployJobContext,
        artifact: DeployArtifact,
        target: DeploymentTarget,
    ) -> DeploymentOutcome:
        return DeploymentOutcome(
            ok=True,
            last_completed_step="deploy_artifact",
            activation_status="external_manual_required",
            message="External origin: deployment is managed outside P2HS.",
            metadata={"adapter": "external_origin", "framework": artifact.framework},
        )

    async def activate_deployment(self, ctx: DeployJobContext) -> DeploymentOutcome:
        return DeploymentOutcome(
            ok=True,
            last_completed_step="activate_deployment",
            activation_status="external_manual_required",
            metadata={"adapter": "external_origin"},
        )

    async def get_deployment_status(self, ctx: DeployJobContext) -> DeploymentOutcome:
        return DeploymentOutcome(
            ok=True,
            activation_status="external_manual_required",
            last_completed_step="get_deployment_status",
            metadata={"adapter": "external_origin"},
        )
