import uuid
from datetime import datetime
from decimal import Decimal
from pydantic import BaseModel, Field


class HoursPayoutCreate(BaseModel):
    user_id: uuid.UUID
    hours: Decimal = Field(gt=0, le=999.99, decimal_places=2)
    period_year: int | None = Field(None, ge=2000, le=2100)
    period_month: int | None = Field(None, ge=1, le=12)
    note: str | None = Field(None, max_length=500)


class HoursPayoutRequest(BaseModel):
    """Mitarbeiter beantragt Auszahlung eigener Überstunden (kein user_id – immer self)."""
    hours: Decimal = Field(gt=0, le=999.99, decimal_places=2)
    period_year: int | None = Field(None, ge=2000, le=2100)
    period_month: int | None = Field(None, ge=1, le=12)
    note: str | None = Field(None, max_length=500)


class HoursPayoutReject(BaseModel):
    rejection_reason: str | None = Field(None, max_length=500)


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

    id: uuid.UUID
    company_id: uuid.UUID
    user_id: uuid.UUID
    user_name: str = ""          # Computed: first_name + last_name (wird im Router gesetzt)
    hours: Decimal
    period_year: int | None
    period_month: int | None
    note: str | None
    status: str = "approved"
    rejection_reason: str | None = None
    created_by: uuid.UUID
    created_by_name: str = ""    # Computed im Router
    decided_by: uuid.UUID | None = None
    decided_by_name: str = ""    # Computed im Router
    decided_at: datetime | None = None
    created_at: datetime


class HoursPayoutListResponse(BaseModel):
    payouts: list[HoursPayoutOut]
    total_count: int
