from datetime import datetime, timezone

import pytest
from pydantic import ValidationError

from v1.schedule_items.schemas import (
    AttachmentType,
    ScheduleItemCreateRequest,
    ScheduleItemMetadata,
    ScheduleItemMetadataAttachment,
    ScheduleItemUpdateRequest,
)


def test_create_request_valid() -> None:
    request = ScheduleItemCreateRequest(
        title="Test Event",
        start_at=datetime(2026, 2, 28, 16, 0, 0, tzinfo=timezone.utc),
    )
    assert request.title == "Test Event"
    assert request.timezone == "UTC"


def test_create_request_with_end_at() -> None:
    request = ScheduleItemCreateRequest(
        title="Test Event",
        start_at=datetime(2026, 2, 28, 16, 0, 0, tzinfo=timezone.utc),
        end_at=datetime(2026, 2, 28, 17, 30, 0, tzinfo=timezone.utc),
    )
    assert request.end_at is not None


def test_create_request_invalid_title_empty() -> None:
    with pytest.raises(ValidationError):
        ScheduleItemCreateRequest(
            title="",
            start_at=datetime(2026, 2, 28, 16, 0, 0, tzinfo=timezone.utc),
        )


def test_create_request_invalid_title_too_long() -> None:
    with pytest.raises(ValidationError):
        ScheduleItemCreateRequest(
            title="x" * 256,
            start_at=datetime(2026, 2, 28, 16, 0, 0, tzinfo=timezone.utc),
        )


def test_create_request_with_metadata() -> None:
    metadata = ScheduleItemMetadata(
        color="#FF6B6B",
        location="Meeting Room A",
        notes="Bring documents",
        attachments=[],
    )
    request = ScheduleItemCreateRequest(
        title="Test Event",
        start_at=datetime(2026, 2, 28, 16, 0, 0, tzinfo=timezone.utc),
        metadata=metadata,
    )
    assert request.metadata is not None
    assert request.metadata.color == "#FF6B6B"


def test_update_request_partial() -> None:
    request = ScheduleItemUpdateRequest(title="Updated Title")
    assert request.title == "Updated Title"
    assert request.description is None


def test_metadata_attachment_document() -> None:
    attachment = ScheduleItemMetadataAttachment(
        name="document.pdf",
        type=AttachmentType.DOCUMENT,
        url="https://example.com/doc.pdf",
    )
    assert attachment.type == AttachmentType.DOCUMENT
    assert attachment.url == "https://example.com/doc.pdf"


def test_metadata_attachment_reminder() -> None:
    attachment = ScheduleItemMetadataAttachment(
        name="reminder",
        type=AttachmentType.REMINDER,
        content="Don't forget!",
    )
    assert attachment.type == AttachmentType.REMINDER
    assert attachment.content == "Don't forget!"
