"""Tests for wiki/rdf/context.py -- URI builders and @context."""

from __future__ import annotations

import os

import pytest

from pycharter.wiki.rdf.context import (
    DEFAULT_BASE_URI,
    JSONLD_CONTEXT,
    concept_uri,
    field_uri,
    get_base_uri,
    scheme_uri,
    set_base_uri,
)


class TestURIBuilders:
    def setup_method(self):
        set_base_uri(DEFAULT_BASE_URI)

    def test_concept_uri(self):
        assert concept_uri("OrderIdentifier") == (
            "https://statfyi.com/ontology/concept/OrderIdentifier"
        )

    def test_field_uri(self):
        assert field_uri("order_domain", "order_id") == (
            "https://statfyi.com/ontology/contract/order_domain/field/order_id"
        )

    def test_scheme_uri(self):
        assert scheme_uri("StatFYI") == "https://statfyi.com/ontology/scheme/StatFYI"

    def test_set_base_uri(self):
        set_base_uri("https://custom.org/vocab")
        assert concept_uri("Foo") == "https://custom.org/vocab/concept/Foo"
        set_base_uri(DEFAULT_BASE_URI)

    def test_base_uri_trailing_slash(self):
        set_base_uri("https://example.com/ont")
        assert get_base_uri() == "https://example.com/ont/"
        set_base_uri(DEFAULT_BASE_URI)


class TestJSONLDContext:
    def test_has_skos(self):
        assert "skos" in JSONLD_CONTEXT
        assert JSONLD_CONTEXT["skos"] == "http://www.w3.org/2004/02/skos/core#"

    def test_has_custom_namespace(self):
        assert "statfyi" in JSONLD_CONTEXT

    def test_has_field_mapping_aliases(self):
        assert "mapsTo" in JSONLD_CONTEXT
        assert "tag" in JSONLD_CONTEXT
