# Copyright (c) 2025 CoReason, Inc.
#
# This software is proprietary and dual-licensed.
# Licensed under the Prosperity Public License 3.0 (the "License").
# A copy of the license is available at https://prosperitylicense.com/versions/3.0.0
# For details, see the LICENSE file.
# Commercial use beyond a 30-day trial requires a separate license.
#
# Source Code: https://github.com/CoReason-AI/coreason-manifest


from coreason_manifest.spec.v2.definitions import ManifestMetadata
from coreason_manifest.spec.v2.recipe import (
    AgentNode,
    GraphTopology,
    PolicyConfig,
    RecipeDefinition,
    RecipeInterface,
)


def test_protocol_fields_existence() -> None:
    """Test Case 1: Protocol Fields Existence"""
    policy = PolicyConfig(
        safety_preamble="Strict HIPAA compliance required",
        legal_disclaimer="Not legal advice",
    )

    # Assertion: Verify the fields are correctly stored.
    assert policy.safety_preamble == "Strict HIPAA compliance required"
    assert policy.legal_disclaimer == "Not legal advice"

    # Assertion: Verify the object serializes to JSON correctly.
    json_output = policy.model_dump_json()
    assert "Strict HIPAA compliance required" in json_output
    assert "Not legal advice" in json_output


def test_integration_with_recipe() -> None:
    """Test Case 2: Integration with Recipe"""
    policy = PolicyConfig(
        safety_preamble="Do not offer medical advice",
        legal_disclaimer="Generated by AI",
    )

    recipe = RecipeDefinition(
        metadata=ManifestMetadata(
            name="Governance Test Recipe",
        ),
        interface=RecipeInterface(),
        policy=policy,
        topology=GraphTopology(
            nodes=[
                AgentNode(id="start", agent_ref="agent-1"),
            ],
            edges=[],
            entry_point="start",
        ),
    )

    # Assertion: Verify the recipe validates successfully.
    # (The creation itself validates it, but we can double check fields)
    assert recipe.policy is not None
    assert recipe.policy.safety_preamble == "Do not offer medical advice"
    assert recipe.policy.legal_disclaimer == "Generated by AI"

    # Check full serialization
    dumped = recipe.model_dump()
    assert dumped["policy"]["safety_preamble"] == "Do not offer medical advice"
    assert dumped["policy"]["legal_disclaimer"] == "Generated by AI"
