"""Built-in service specs — the federation's own self-hosted infra as code.

The first customer is **devpi** (the self-hosted package index, replacing the
Codeberg PyPI registry). The flavour / image / network here are the values
resolved + validated in Phase 0 (`~/.claude/plans/phase0-results-2026-06-18.md`):
``a2-ram4-disk50-perf1`` (2 vCPU / 4 GB / 50 GB) on ``ext-net1`` (direct-public,
so the host is reachable at ``<ip>.sslip.io``).
"""

from __future__ import annotations

from mgf.cloud_provision.models import ServiceSpec

__all__ = ["DEVPI_CLOUD_INIT", "devpi_service_spec"]

# Minimal cloud-init placeholder. Phase 1b fleshes this out: a devpi-server +
# devpi-web venv, a Caddy(Let's Encrypt) reverse proxy on <ip>.sslip.io -> :3141,
# systemd units, index init (root/pypi pull-through cache + magogi/prod +
# magogi/dev inheriting it), and a nightly devpi-export backup to object storage.
DEVPI_CLOUD_INIT = """#cloud-config
package_update: true
packages:
  - python3-venv
  - python3-pip
# TODO(phase-1b): install devpi-server>=6.10,<7 + devpi-web>=4.2,<5 into a venv;
# install Caddy (auto-TLS via Let's Encrypt) reverse-proxying :443 -> :3141;
# systemd units; init indexes root/pypi (cache), magogi/prod, magogi/dev.
"""


def devpi_service_spec(*, key_name: str | None = None) -> ServiceSpec:
    """The Phase-0-resolved spec for the federation's devpi index host."""
    return ServiceSpec(
        name="devpi-prod",
        flavor="a2-ram4-disk50-perf1",
        image="Ubuntu 24.04 LTS Noble Numbat",
        provider="infomaniak",
        network="ext-net1",
        key_name=key_name,
        security_groups=("devpi-prod",),
        cloud_init=DEVPI_CLOUD_INIT,
        owner="mgf-cloud-provision",
    )
