import unittest

from pydantic import ValidationError

from web.schemas import MessageRequest


class MessageAttachmentSchemaTests(unittest.TestCase):
    def test_omitted_attachments_remains_distinguishable_for_legacy_clients(self):
        body = MessageRequest(content="旧客户端正文")
        self.assertEqual(body.attachments, [])
        self.assertNotIn("attachments", body.model_fields_set)

    def test_explicit_structured_attachments_are_accepted(self):
        body = MessageRequest(
            content="分析图片",
            attachments=[{"path": "任务/a.png", "kind": "image"}],
        )
        self.assertIn("attachments", body.model_fields_set)
        self.assertEqual(body.attachments[0].path, "任务/a.png")

    def test_attachment_count_is_limited(self):
        with self.assertRaises(ValidationError):
            MessageRequest(
                content="太多",
                attachments=[{"path": f"任务/{i}.txt"} for i in range(11)],
            )
