"""Shared test fixtures."""

from __future__ import annotations

import json
from pathlib import Path
from typing import Any

import pytest


@pytest.fixture()
def sample_server() -> dict[str, Any]:
    """A single realistic Hetzner auction server entry."""
    return {
        "id": 9999,
        "cpu": "AMD Ryzen 9 5950X",
        "ram_size": 128,
        "price": 65.0,
        "is_ecc": True,
        "datacenter": "FSN1-DC14",
        "bandwidth": 1000,
        "hdd_arr": ["512 GB NVMe SSD", "512 GB NVMe SSD", "4 TB HDD", "4 TB HDD"],
        "specials": ["iNIC"],
        "description": [],
        "serverDiskData": {
            "nvme": [512, 512],
            "sata": [],
            "hdd": [4000, 4000],
        },
    }


@pytest.fixture()
def sample_servers(sample_server: dict[str, Any]) -> list[dict[str, Any]]:
    """A list of three servers with different characteristics."""
    return [
        sample_server,
        {
            "id": 8888,
            "cpu": "Intel Xeon E3-1271V3",
            "ram_size": 32,
            "price": 30.0,
            "is_ecc": True,
            "datacenter": "HEL1-DC2",
            "bandwidth": 1000,
            "hdd_arr": ["256 GB SSD", "256 GB SSD"],
            "specials": [],
            "description": [],
            "serverDiskData": {"nvme": [], "sata": [256, 256], "hdd": []},
        },
        {
            "id": 7777,
            "cpu": "Intel Core i7-8700",
            "ram_size": 64,
            "price": 45.0,
            "is_ecc": False,
            "datacenter": "NBG1-DC3",
            "bandwidth": 1000,
            "hdd_arr": ["1 TB NVMe SSD"],
            "specials": ["GPU"],
            "description": ["NVIDIA RTX 3060"],
            "serverDiskData": {"nvme": [1000], "sata": [], "hdd": []},
        },
    ]


@pytest.fixture()
def tmp_config(tmp_path: Path) -> Path:
    """Write a test config file and return its path."""
    config = tmp_path / "sb-scout.toml"
    config.write_text("""\
[defaults]
top = 3

[defaults.filters]
ecc_only = false

[defaults.bonuses]
inic = 0.20

[profiles.test-budget]
description = "Test budget profile"

[profiles.test-budget.filters]
price_cap = 50.0

[cpu_specs]
"Fake CPU 9000" = { cores = 128, threads = 256 }
""")
    return config
