"""Shared test fixtures — Case builders for the worker-line tests."""

from __future__ import annotations

from datetime import datetime, timedelta, timezone
from typing import Optional

import pytest

from psyc.models import Case, Classification, IncidentType, Observables, Severity, TLP


def make_case(
    feed: str = "urlhaus",
    incident_type: Optional[IncidentType] = None,
    severity: Optional[Severity] = None,
    tlp: TLP = TLP.AMBER,
    country: str = "",
    age_days: int = 1,
    **observables: list,
) -> Case:
    """A Case with controllable feed, classification, age, and observables."""
    case = Case(
        case_id=f"TEST-{feed}-{age_days}",
        summary=f"test case from {feed}",
        source_type="abuse_feed",
        observed_at=datetime.now(timezone.utc) - timedelta(days=age_days),
        observables=Observables(**observables),
        classification=Classification(incident_type=incident_type, severity=severity, tlp=tlp),
    )
    case.source_metadata["feed"] = feed
    case.victim.country = country
    return case


@pytest.fixture
def urlhaus_case() -> Case:
    c = make_case(feed="urlhaus", urls=["http://1.2.3.4/x"], domains=["1.2.3.4"], ips=["1.2.3.4"])
    c.source_metadata["url_status"] = "online"
    return c
