"""
Canvas-related schemas.
"""
from typing import List, Optional, Dict, Any
from datetime import datetime
from pydantic import BaseModel, Field, ConfigDict


class CanvasState(BaseModel):
    id: str = "default"
    projectId: Optional[str] = Field(None, alias="projectId")
    nodes: List[Dict[str, Any]] = []
    connections: List[Dict[str, Any]] = []
    groups: List[Dict[str, Any]] = []
    history: List[Dict[str, Any]] = []
    history_index: int = Field(-1, alias="historyIndex")
    updated_at: float = Field(default_factory=lambda: datetime.now().timestamp(), alias="updatedAt")

    model_config = ConfigDict(populate_by_name=True)


class CanvasMetadata(BaseModel):
    """Canvas metadata"""
    id: str
    project_id: str = Field(alias="projectId")
    canvas_type: str = Field(alias="canvasType")
    related_entity_type: Optional[str] = Field(None, alias="relatedEntityType")
    related_entity_id: Optional[str] = Field(None, alias="relatedEntityId")
    name: str
    description: Optional[str] = None
    order_index: int = Field(alias="orderIndex")
    is_pinned: bool = Field(alias="isPinned")
    tags: List[str] = []
    node_count: int = Field(alias="nodeCount")
    last_accessed_at: Optional[float] = Field(None, alias="lastAccessedAt")
    access_count: int = Field(alias="accessCount")
    created_at: float = Field(alias="createdAt")
    updated_at: float = Field(alias="updatedAt")
    deleted_at: Optional[float] = Field(None, alias="deletedAt")

    model_config = ConfigDict(populate_by_name=True)


class CreateGeneralCanvasRequest(BaseModel):
    """Create general canvas request"""
    name: str = Field(..., description="Canvas name")
    description: Optional[str] = Field(None, description="Canvas description")

    model_config = ConfigDict(populate_by_name=True)


class UpdateCanvasMetadataRequest(BaseModel):
    """Update canvas metadata request"""
    name: Optional[str] = None
    description: Optional[str] = None
    is_pinned: Optional[bool] = Field(None, alias="isPinned")
    tags: Optional[List[str]] = None

    model_config = ConfigDict(populate_by_name=True)
