# generated by copilot

import json
from typing import Optional

from cookit.pyd import (
    get_model_with_config,
    model_config,
    model_dump,
    type_validate_json,
    type_validate_python,
)
from pydantic import BaseModel, ConfigDict

# region from nonebot2


async def test_model_dump():
    class TestModel(BaseModel):
        test1: int
        test2: int

    assert model_dump(TestModel(test1=1, test2=2), include={"test1"}) == {"test1": 1}
    assert model_dump(TestModel(test1=1, test2=2), exclude={"test1"}) == {"test2": 2}


async def test_validate():
    class TestModel(BaseModel):
        test1: int
        test2: str
        test3: bool
        test4: dict
        test5: list
        test6: Optional[int]

    data = {
        "test1": 1,
        "test2": "2",
        "test3": True,
        "test4": {},
        "test5": [],
        "test6": None,
    }
    expected = TestModel(test1=1, test2="2", test3=True, test4={}, test5=[], test6=None)
    assert type_validate_python(TestModel, data) == expected
    assert type_validate_json(TestModel, json.dumps(data)) == expected


# endregion


async def test_get_model_with_config():
    config = ConfigDict(arbitrary_types_allowed=True)
    Model = get_model_with_config(config)  # noqa: N806
    assert isinstance(Model(), Model)
    for k in config:
        assert model_config(Model)[k] == config[k]
