from datetime import datetime

from sqgen_risk.models import InferenceRequest, Model


def test_model_from_dict() -> None:
    """Test creating a Model from a dictionary."""
    data = {"id": 1, "model_id": "model-1", "user_id": "user-1", "name": "Test Model"}

    model = Model.from_dict(data)

    assert model.id == 1
    assert model.model_id == "model-1"
    assert model.user_id == "user-1"
    assert model.name == "Test Model"


def test_inference_request_from_dict() -> None:
    """Test creating an InferenceRequest from a dictionary."""
    data = {
        "id": 1,
        "user_id": "user-1",
        "inference_request_id": "request-1",
        "model_id": "model-1",
        "created_at": "2025-06-29T12:00:00",
        "result_retrieved_at": None,
    }

    inference = InferenceRequest.from_dict(data)

    assert inference.id == 1
    assert inference.user_id == "user-1"
    assert inference.inference_request_id == "request-1"
    assert inference.model_id == "model-1"
    assert inference.created_at == datetime.fromisoformat("2025-06-29T12:00:00")
    assert inference.result_retrieved_at is None


def test_inference_request_from_dict_with_result() -> None:
    """Test creating an InferenceRequest with result retrieved."""
    data = {
        "id": 1,
        "user_id": "user-1",
        "inference_request_id": "request-1",
        "model_id": "model-1",
        "created_at": "2025-06-29T12:00:00",
        "result_retrieved_at": "2025-06-30T12:00:00",
    }

    inference = InferenceRequest.from_dict(data)

    assert inference.created_at == datetime.fromisoformat("2025-06-29T12:00:00")
    assert inference.result_retrieved_at == datetime.fromisoformat("2025-06-30T12:00:00")
