"""Tests for OrxaqAPI routes."""

from __future__ import annotations

from orxaq.experiences.api import OrxaqAPI


class TestAPIRoutes:
    def setup_method(self):
        self.api = OrxaqAPI()

    def test_status(self):
        data, status = self.api.handle("/api/status")
        assert status == 200
        assert "dag" in data
        assert "audit_entries" in data

    def test_ontology(self):
        data, status = self.api.handle("/api/ontology")
        assert status == 200
        assert data["entity_count"] == 19
        assert len(data["entities"]) == 19
        assert len(data["edges"]) > 0

    def test_ecl(self):
        data, status = self.api.handle("/api/ecl")
        assert status == 200
        assert data["total_ecl"] > 0
        assert "horizon_quarters" in data
        assert "confidence_band" in data

    def test_stress(self):
        data, status = self.api.handle("/api/stress")
        assert status == 200
        assert "base_pd" in data
        assert "stress_pd" in data
        assert "delta" in data

    def test_fairness(self):
        data, status = self.api.handle("/api/fairness")
        assert status == 200
        assert data["protected_var"] == "age"
        assert "direct_effect" in data
        assert "indirect_effects" in data

    def test_discover(self):
        data, status = self.api.handle("/api/discover")
        assert status == 200
        assert "edges" in data
        assert "algorithms_used" in data

    def test_validate(self):
        data, status = self.api.handle("/api/validate")
        assert status == 200
        assert "total_implications" in data
        assert "violations" in data
        assert isinstance(data["passed"], bool)

    def test_audit(self):
        data, status = self.api.handle("/api/audit")
        assert status == 200
        assert "entries" in data
        assert isinstance(data["entries"], list)

    def test_unknown_route(self):
        data, status = self.api.handle("/api/unknown")
        assert status == 404
        assert data["error"] == "not_found"
