import uuid
from datetime import datetime

from pydantic import BaseModel, Field


class ProjectOut(BaseModel):
    model_config = {"from_attributes": True}

    id: uuid.UUID
    company_id: uuid.UUID
    name: str
    description: str | None
    color: str
    budget_hours: float | None
    is_active: bool
    created_at: datetime
    updated_at: datetime


class ProjectCreate(BaseModel):
    name: str = Field(min_length=1, max_length=100)
    description: str | None = None
    color: str = Field("#3B82F6", pattern=r"^#[0-9A-Fa-f]{6}$")
    budget_hours: float | None = Field(None, ge=0.1, le=99999)


class ProjectUpdate(BaseModel):
    name: str | None = Field(None, min_length=1, max_length=100)
    description: str | None = None
    color: str | None = Field(None, pattern=r"^#[0-9A-Fa-f]{6}$")
    budget_hours: float | None = Field(None, ge=0.1, le=99999)
    is_active: bool | None = None


class ProjectListResponse(BaseModel):
    total: int
    items: list[ProjectOut]


class ProjectTimeReport(BaseModel):
    project_id: uuid.UUID
    project_name: str
    project_color: str
    total_hours: float
    entry_count: int
    budget_hours: float | None
    budget_used_pct: float | None  # None wenn kein Budget
