from datetime import datetime, timezone

import pytest

from cogos.io.base import InboundEvent, IOAdapter, IOMode


class TestInboundEvent:
    def test_create_minimal(self):
        event = InboundEvent(source="discord", message_type="dm", payload={}, raw_content="hello")
        assert event.source == "discord"
        assert event.message_type == "dm"
        assert event.author is None

    def test_create_full(self):
        now = datetime.now(timezone.utc)
        event = InboundEvent(
            source="github",
            message_type="push",
            payload={"ref": "main"},
            raw_content="pushed to main",
            author="daveey",
            timestamp=now,
            external_id="github:push:123",
            external_url="https://github.com/org/repo/commit/abc",
        )
        assert event.payload == {"ref": "main"}
        assert event.author == "daveey"
        assert event.timestamp == now
        assert event.external_id == "github:push:123"


class TestIOMode:
    def test_modes_exist(self):
        assert IOMode.LIVE.value == "live"
        assert IOMode.POLL.value == "poll"
        assert IOMode.ON_DEMAND.value == "on_demand"


class TestIOAdapterABC:
    def test_cannot_instantiate_abstract(self):
        with pytest.raises(TypeError):
            IOAdapter(name="test")  # type: ignore[reportAbstractUsage]
