"""Tests for ServersResource."""

from __future__ import annotations

import httpx
import pytest

from appliku import Appliku


@pytest.fixture()
def server_data() -> dict[str, object]:
    return {
        "id": 1,
        "name": "web-1",
        "provider": "digitalocean",
        "region": "nyc1",
        "status": "active",
    }


class TestServersList:
    def test_list_returns_servers(
        self,
        mock_client: tuple[Appliku, list[httpx.Response]],
        server_data: dict[str, object],
    ) -> None:
        client, responses = mock_client
        responses.append(httpx.Response(200, json=[server_data]))
        result = client.servers.list("acme")
        assert len(result) == 1
        assert result[0].provider == "digitalocean"


class TestServersCreateDO:
    def test_create_do_returns_server(
        self, mock_client: tuple[Appliku, list[httpx.Response]], server_data: dict[str, object]
    ) -> None:
        client, responses = mock_client
        responses.append(httpx.Response(201, json=server_data))
        server = client.servers.create_digitalocean("acme", "web-1", "nyc1", "s-1vcpu-1gb")
        assert server.name == "web-1"


class TestServersCreateEC2:
    def test_create_ec2_returns_server(
        self, mock_client: tuple[Appliku, list[httpx.Response]]
    ) -> None:
        client, responses = mock_client
        ec2_data = {
            "id": 2,
            "name": "worker-1",
            "provider": "ec2",
            "region": "us-east-1",
            "status": "active",
        }
        responses.append(httpx.Response(201, json=ec2_data))
        server = client.servers.create_ec2("acme", "worker-1", "us-east-1", "t3.large")
        assert server.provider == "ec2"


class TestServersCreateCustom:
    def test_create_custom_returns_server(
        self, mock_client: tuple[Appliku, list[httpx.Response]]
    ) -> None:
        client, responses = mock_client
        custom_data = {
            "id": 3,
            "name": "bare-metal",
            "provider": "custom",
            "region": None,
            "status": "active",
        }
        responses.append(httpx.Response(201, json=custom_data))
        server = client.servers.create_custom("acme", "bare-metal", "203.0.113.1")
        assert server.name == "bare-metal"
