"""Root-level shared pytest configuration and fixtures.

Provides common fixtures used across all test modules:
- tmp_workspace: temporary directory with standard subdirectories
- synthetic_credit_data: sample credit data for validation/credit tests
- mock_dag: simple DAG structure for causal module tests
- sample_config: minimal orxaq configuration dict

Custom marks: slow, integration, smoke
"""

from __future__ import annotations

import pytest

# ---------------------------------------------------------------------------
# Custom marks (also declared in pyproject.toml [tool.pytest.ini_options])
# ---------------------------------------------------------------------------


def pytest_configure(config: pytest.Config) -> None:
    """Register custom markers to avoid unknown-marker warnings."""
    config.addinivalue_line("markers", "slow: marks tests as slow")
    config.addinivalue_line(
        "markers", "integration: marks integration tests requiring external services"
    )
    config.addinivalue_line("markers", "smoke: marks quick smoke tests for CI fast-path")


# ---------------------------------------------------------------------------
# Fixtures
# ---------------------------------------------------------------------------


@pytest.fixture()
def tmp_workspace(tmp_path):
    """Create a temporary workspace with standard subdirectories.

    Returns a ``pathlib.Path`` pointing to the workspace root, with the
    following subdirectories already created:

    - data/
    - config/
    - output/
    - logs/
    """
    for subdir in ("data", "config", "output", "logs"):
        (tmp_path / subdir).mkdir()
    return tmp_path


@pytest.fixture()
def synthetic_credit_data():
    """Return a dict with sample credit data fields for testing.

    Fields mirror common credit-risk attributes used throughout the
    validation and credit modules.
    """
    return {
        "loan_id": "LN-2024-00001",
        "loan_amount": 250_000.00,
        "interest_rate": 0.045,
        "credit_score": 720,
        "debt_to_income": 0.35,
        "loan_to_value": 0.80,
        "term_months": 360,
        "origination_date": "2024-01-15",
        "default_flag": 0,
        "delinquency_days": 0,
        "loss_given_default": 0.40,
        "probability_of_default": 0.02,
        "exposure_at_default": 250_000.00,
        "expected_loss": 2_000.00,
    }


@pytest.fixture()
def mock_dag():
    """Return a simple directed acyclic graph as a dict of node -> edges.

    The graph represents a small causal model::

        A -> B -> D
        A -> C -> D
              C -> E
    """
    return {
        "A": ["B", "C"],
        "B": ["D"],
        "C": ["D", "E"],
        "D": [],
        "E": [],
    }


@pytest.fixture()
def sample_config():
    """Return a minimal orxaq configuration dict.

    Suitable for tests that need a configuration object without loading
    from disk or environment variables.
    """
    return {
        "project_name": "orxaq-test",
        "version": "0.0.0-test",
        "log_level": "DEBUG",
        "data_dir": "/tmp/orxaq-test-data",
        "output_dir": "/tmp/orxaq-test-output",
        "database": {
            "engine": "sqlite",
            "path": ":memory:",
        },
        "dag": {
            "default_backend": "networkx",
            "max_nodes": 1000,
        },
        "credit": {
            "default_lgd": 0.40,
            "default_pd_model": "logistic",
            "scenarios": ["base", "adverse", "severely_adverse"],
        },
    }
