"""Tests for VolumesResource."""

from __future__ import annotations

import httpx
import pytest

from appliku import Appliku


@pytest.fixture()
def volume_data() -> dict[str, object]:
    return {
        "id": 1,
        "name": "data-vol",
        "container_path": "/data",
        "url": "s3://bucket/vol",
        "environment_variable": "DATA_PATH",
    }


class TestVolumesList:
    def test_list_returns_paginated(
        self,
        mock_client: tuple[Appliku, list[httpx.Response]],
        volume_data: dict[str, object],
        paginated_response: object,
    ) -> None:
        client, responses = mock_client
        responses.append(httpx.Response(200, json=paginated_response([volume_data])))  # type: ignore[operator]
        result = client.volumes.list("acme", 42)
        assert result.count == 1
        assert result.results[0].name == "data-vol"


class TestVolumesCreate:
    def test_create_returns_volume(
        self, mock_client: tuple[Appliku, list[httpx.Response]], volume_data: dict[str, object]
    ) -> None:
        client, responses = mock_client
        responses.append(httpx.Response(201, json=volume_data))
        vol = client.volumes.create("acme", 42, "data-vol", "/data")
        assert vol.id == 1


class TestVolumesUpdate:
    def test_update_returns_volume(self, mock_client: tuple[Appliku, list[httpx.Response]]) -> None:
        client, responses = mock_client
        updated = {"id": 1, "name": "renamed", "container_path": "/data"}
        responses.append(httpx.Response(200, json=updated))
        vol = client.volumes.update("acme", 42, 1, name="renamed")
        assert vol.name == "renamed"


class TestVolumesDelete:
    def test_delete_succeeds(self, mock_client: tuple[Appliku, list[httpx.Response]]) -> None:
        client, responses = mock_client
        responses.append(httpx.Response(204))
        client.volumes.delete("acme", 42, 1)
