"""Unit tests for core/onboarding.py (P19, REQ-183)."""

import json
import sys
from pathlib import Path

import pytest

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

from core.onboarding import generate_env_file, _onboarding_request_message


class TestGenerateEnvFile:
    """P19 (REQ-183): generate_env_file produces a valid env JSON."""

    def test_generates_env_with_request_fields(self):
        request = {
            "consumerRepo": "acdl/consumer-b",
            "requestedEnvironment": "qa",
            "ownerId": "team-b",
            "billingTag": "cost-center-b",
        }
        env = generate_env_file(request, template_env="dev")
        assert env["name"] == "qa"
        assert env["ownerId"] == "team-b"
        assert env["billingTag"] == "cost-center-b"
        assert env["account_id"] == "000000000000"  # placeholder
        assert "consumer-b" in env["description"]

    def test_preserves_template_network_and_state(self):
        request = {
            "consumerRepo": "acdl/c",
            "requestedEnvironment": "prod",
            "ownerId": "team-a",
            "billingTag": "cc-a",
        }
        env = generate_env_file(request, template_env="dev")
        assert "vpc_cidr" in env["network"]
        assert "bucket" in env["state_backend"]
        assert env["region"] == "us-east-1"


class TestOnboardingRequestMessage:
    """P19 (REQ-183): the request message is self-service."""

    def test_message_mentions_onboard_consumer(self):
        msg = _onboarding_request_message("dev")
        assert "onboard_consumer" in msg
        assert "Nova" in msg