"""Project models"""

from datetime import datetime
from typing import Dict, List, Optional
from uuid import uuid4
from pydantic import BaseModel, Field, ConfigDict
from .theme import Theme
from .component import Component


class ProjectMetadata(BaseModel):
    """Project metadata"""
    created_at: datetime = Field(default_factory=datetime.utcnow)
    updated_at: datetime = Field(default_factory=datetime.utcnow)
    author: Optional[str] = None
    team: Optional[str] = None
    tags: List[str] = Field(default_factory=list)


class Project(BaseModel):
    """A design system project"""
    model_config = ConfigDict(arbitrary_types_allowed=True)

    id: str = Field(..., description="Unique project ID")
    uuid: str = Field(default_factory=lambda: str(uuid4()), description="UUID for export/import")
    name: str = Field(..., description="Project name")
    version: str = Field(default="1.0.0", description="Project version")
    description: Optional[str] = Field(None, description="Project description")
    theme: Theme = Field(..., description="Project theme configuration")
    components: List[Component] = Field(default_factory=list, description="Project components")
    metadata: ProjectMetadata = Field(default_factory=ProjectMetadata)

    def get_component(self, name: str) -> Optional[Component]:
        """Get component by name"""
        for component in self.components:
            if component.name == name:
                return component
        return None
