import sqlite3
from datetime import UTC, datetime
from pathlib import Path

import pytest

from worker_watcher.config import AppConfig, CollectorConfig, WatcherConfig
from worker_watcher.db.connection import connect
from worker_watcher.db.migrations import apply_migrations


@pytest.fixture
def now() -> datetime:
    return datetime(2026, 7, 31, 12, 0, tzinfo=UTC)


@pytest.fixture
def connection(tmp_path: Path) -> sqlite3.Connection:
    connection = connect(tmp_path / "watcher.sqlite")
    apply_migrations(connection)
    yield connection
    connection.close()


def app_config(path: Path, collector_types: tuple[str, ...] = ("generic_worker",)) -> AppConfig:
    return AppConfig(
        watcher=WatcherConfig(database_path=path),
        collectors=tuple(CollectorConfig(name=kind, type=kind, definitions=()) for kind in collector_types),
    )
