"""Common schemas used across multiple API endpoints."""

import datetime
from typing import Any, Generic, TypeVar
from uuid import UUID
from ..model import Schema, Field

T = TypeVar("T")


class BaseSchema(Schema):
    """Base schema with camelCase alias generation."""

    ...


class BaseResponse(BaseSchema):
    """Base response schema with common configuration."""

    pass


class PaginationParams(BaseSchema):
    """Standard pagination parameters."""

    page: int = Field(default=1, ge=1, description="Page number")
    size: int = Field(default=10, ge=1, le=100, description="Page size")


class PaginatedResponse(BaseSchema, Generic[T]):
    """Generic paginated response wrapper."""

    items: list[T] = Field(..., description="List of items")
    total: int = Field(..., description="Total number of items")
    page: int = Field(..., description="Current page number")
    size: int = Field(..., description="Page size")


class StatusUpdateRequest(BaseSchema):
    """Generic status update request."""

    status: str = Field(..., description="New status value")


class IDResponse(BaseSchema):
    """Simple response containing just an ID."""

    id: UUID = Field(..., description="Resource identifier")


class BulkResponse(BaseSchema):
    """Response for bulk operations."""

    created: int = Field(..., description="Number of items created")
    updated: int = Field(..., description="Number of items updated")
    deleted: int = Field(..., description="Number of items deleted")
    errors: list[str] | None = Field(None, description="Any errors encountered")


# Event base schemas
class BaseEventCreateRequest(BaseSchema):
    """Base request schema for creating events."""

    event_type: str = Field(..., description="Type of the event", max_length=128)
    event_text: str | None = Field(None, description="Descriptive text about the event")
    details: dict[str, Any] | list[Any] | None = Field(
        None, description="Additional details about the event in JSON format"
    )


class BaseEventResponse(BaseResponse):
    """Base response schema for event data."""

    id: UUID = Field(..., description="Unique identifier for the event")
    event_timestamp: datetime.datetime = Field(
        ..., description="Event timestamp in UTC"
    )
    user_id: UUID = Field(
        ..., description="Identifier of the user who triggered the event"
    )
    event_type: str = Field(..., description="Type of the event")
    event_text: str | None = Field(None, description="Descriptive text about the event")
    details: dict[str, Any] | list[Any] | None = Field(
        None, description="Additional details about the event in JSON format"
    )
