import pytest
from api.v1.modules.public.reference_data.valuation_methods.routes import router
from fastapi import FastAPI
from fastapi.testclient import TestClient

app = FastAPI()
app.include_router(router)
client = TestClient(app)


@pytest.mark.usefixtures("client", "access_token")
def test_list_valuation_methods(client, access_token):
    headers = {"Authorization": f"Bearer {access_token}"}
    response = client.get("/valuation-methods/", headers=headers)
    assert response.status_code == 200
    assert "items" in response.json()
    assert "page" in response.json()
    assert "page_size" in response.json()


@pytest.mark.usefixtures("client", "access_token")
def test_get_valuation_method_not_found(client, access_token):
    headers = {"Authorization": f"Bearer {access_token}"}
    response = client.get("/valuation-methods/invalid_key", headers=headers)
    assert response.status_code == 404


def test_create_valuation_method_forbidden():
    response = client.post(
        "/valuation-methods/", json={"key": "TST", "description": "Test"}
    )
    assert response.status_code in (403, 405, 404)


def test_update_valuation_method_forbidden():
    response = client.put(
        "/valuation-methods/TST", json={"key": "TST", "description": "Test"}
    )
    assert response.status_code in (403, 405, 404)


def test_delete_valuation_method_forbidden():
    response = client.delete("/valuation-methods/TST")
    assert response.status_code in (403, 405, 404)
