"""pytest configuration and fixtures for ingress-edge tests."""

from datetime import UTC, datetime

import pytest

from ingress_edge.types import (
    BufferStats,
    IngressClientConfig,
    IngressDataPoint,
    IngressResponse,
)


@pytest.fixture
def sample_data_point():
    """Return a valid IngressDataPoint."""
    return IngressDataPoint(
        channel_id="ch_maritime_telemetry",
        timestamp=datetime.now(UTC),
        data={
            "vessel_id": "v_12345",
            "latitude": 59.9139,
            "longitude": 10.7522,
            "speed": 15.3,
        },
    )


@pytest.fixture
def sample_data_point_dict():
    """Return valid IngressDataPoint data as dict."""
    return {
        "channel_id": "ch_maritime_telemetry",
        "timestamp": datetime.now(UTC).isoformat(),
        "data": {
            "vessel_id": "v_12345",
            "latitude": 59.9139,
            "longitude": 10.7522,
            "speed": 15.3,
        },
    }


@pytest.fixture
def sample_config():
    """Return a valid IngressClientConfig."""
    return IngressClientConfig(
        base_url="http://localhost:8000",
        api_key="test-api-key",
        batch_size=100,
        batch_timeout=5.0,
        max_retries=3,
        offline_buffer_size=1000,
    )


@pytest.fixture
def small_batch_config():
    """Return a config with small batch size for testing."""
    return IngressClientConfig(
        base_url="http://localhost:8000",
        api_key="test-api-key",
        batch_size=3,
        batch_timeout=0.1,
        max_retries=2,
        offline_buffer_size=10,
    )


@pytest.fixture
def success_response():
    """Return a successful IngressResponse."""
    return IngressResponse(
        accepted=1,
        rejected=0,
        errors=None,
    )


@pytest.fixture
def partial_success_response():
    """Return a partial success IngressResponse with some rejections."""
    from ingress_edge.types import IngestError

    return IngressResponse(
        accepted=2,
        rejected=1,
        errors=[IngestError(index=1, reason="Invalid timestamp")],
    )


def make_data_point(channel_id: str = "ch_test") -> IngressDataPoint:
    """Create a data point with given channel ID."""
    return IngressDataPoint(
        channel_id=channel_id,
        timestamp=datetime.now(UTC),
        data={"value": 42},
    )
