from dsg_core.domain.items.schemas import UpdateItem
from dsg_core.services.data.query import QueryParams, QueryParamsV2


def test_query_params_normalize_empty_valid_at_to_none() -> None:
    params = QueryParams.model_validate(
        {
            "itemTypeId": "00000000-0000-0000-0000-000000000001",
            "version": "default",
            "validAt": "",
        }
    )

    assert params.valid_at is None


def test_query_params_v2_normalize_blank_valid_at_to_none() -> None:
    params = QueryParamsV2.model_validate(
        {
            "itemTypeId": "00000000-0000-0000-0000-000000000001",
            "versions": ["default"],
            "validAt": "   ",
        }
    )

    assert params.valid_at is None


def test_update_item_normalizes_empty_val_from_to_none() -> None:
    command = UpdateItem.model_validate(
        {
            "itemTypeId": "00000000-0000-0000-0000-000000000001",
            "itemId": "00000000-0000-0000-0000-000000000002",
            "data": {},
            "valFrom": "",
        }
    )

    assert command.val_from is None
