from pathlib import Path

import pytest

from core.meeting_loader import load_meeting_input
from core.models import MeetingInput


def test_load_meeting_input_from_yaml(tmp_path: Path) -> None:
    path = tmp_path / "meeting.yaml"
    path.write_text(
        """
topic: test topic
brief: {}
decision_packet:
  decision_to_make: decide
""".strip(),
        encoding="utf-8",
    )

    meeting_input = load_meeting_input(path)

    assert meeting_input.topic == "test topic"


def test_load_meeting_input_from_json(tmp_path: Path) -> None:
    path = tmp_path / "meeting.json"
    path.write_text(
        '{"topic": "test topic", "brief": {}, "decision_packet": {"decision_to_make": "decide"}}',
        encoding="utf-8",
    )

    meeting_input = load_meeting_input(path)

    assert meeting_input.decision_packet.decision_to_make == "decide"


def test_load_meeting_input_rejects_missing_topic(tmp_path: Path) -> None:
    path = tmp_path / "meeting.yaml"
    path.write_text(
        """
brief: {}
decision_packet:
  decision_to_make: decide
""".strip(),
        encoding="utf-8",
    )

    with pytest.raises(ValueError):
        load_meeting_input(path)


def test_load_meeting_input_rejects_invalid_decision_packet(tmp_path: Path) -> None:
    path = tmp_path / "meeting.yaml"
    path.write_text(
        """
topic: test topic
brief: {}
decision_packet:
  decision_to_make: ""
""".strip(),
        encoding="utf-8",
    )

    with pytest.raises(ValueError):
        load_meeting_input(path)


def test_load_meeting_input_returns_typed_model(tmp_path: Path) -> None:
    path = tmp_path / "meeting.yaml"
    path.write_text(
        """
topic: typed topic
brief: {}
decision_packet:
  decision_to_make: decide
""".strip(),
        encoding="utf-8",
    )

    meeting_input = load_meeting_input(path)

    assert isinstance(meeting_input, MeetingInput)
