"""Tests for ai4gh.core.types."""

from __future__ import annotations

from ai4gh.core.types import Organization, ServiceInfo, ServiceType


class TestServiceType:
    def test_create(self) -> None:
        st = ServiceType(group="org.ga4gh", artifact="beacon", version="2.0.0")
        assert st.group == "org.ga4gh"
        assert st.artifact == "beacon"
        assert st.version == "2.0.0"


class TestOrganization:
    def test_create(self) -> None:
        org = Organization(name="Test Org", url="https://example.org")
        assert org.name == "Test Org"
        assert org.url == "https://example.org"


class TestServiceInfo:
    def test_minimal(self) -> None:
        si = ServiceInfo(
            id="org.example",
            name="Test Service",
            type=ServiceType(group="org.ga4gh", artifact="drs", version="1.4.0"),
        )
        assert si.id == "org.example"
        assert si.name == "Test Service"
        assert si.type.artifact == "drs"
        assert si.organization is None

    def test_full(self, sample_service_info: dict) -> None:
        si = ServiceInfo.model_validate(sample_service_info)
        assert si.id == "org.ga4gh.test"
        assert si.type.artifact == "beacon"
        assert si.organization is not None
        assert si.organization.name == "Test Organization"
        assert si.version == "1.0.0"

    def test_extra_fields_allowed(self) -> None:
        si = ServiceInfo(
            id="test",
            name="Test",
            type=ServiceType(group="org.ga4gh", artifact="drs", version="1.0"),
            custom_field="extra",
        )
        assert si.id == "test"
