#!/usr/bin/env python3
"""Generate docker/.env with random secrets for local Compose."""

from __future__ import annotations

import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parent.parent
if str(ROOT) not in sys.path:
    sys.path.insert(0, str(ROOT))

from scripts.generate_nexus_secrets import (  # noqa: E402
    generate_nexus_secrets,
    write_env_prod,
)

OUT = ROOT / "docker" / ".env"
EXAMPLE = ROOT / "docker" / ".env.example"


def main() -> None:
    if OUT.exists():
        raise SystemExit(f"Refusing to overwrite existing {OUT} — delete it first.")

    secrets_map = generate_nexus_secrets()
    write_env_prod(
        EXAMPLE,
        OUT,
        domain="localhost",
        secrets_map=secrets_map,
        profile_env=None,
        wizard_pending=False,
    )
    print(f"Wrote {OUT}")
    print("Next: docker compose up -d --build")


if __name__ == "__main__":
    main()
