"""Permission models for vikdata API."""

from uuid import UUID

from pydantic import BaseModel, Field


class PermissionBase(BaseModel):
    """Base permission model."""

    resource: str = Field(..., description="Resource name (e.g., 'users', 'fishinfo:species')")
    action: str = Field(..., description="Action (read, write, delete, manage)")
    scope: str = Field(..., description="Scope (* for all, 'tenant', 'own')")
    description: str | None = Field(default=None, description="Permission description")


class PermissionResponse(PermissionBase):
    """Permission response."""

    id: UUID = Field(..., description="Permission ID")
    service: str | None = Field(default=None, description="Service name if microservice permission")


class PermissionListResponse(BaseModel):
    """Paginated list of permissions."""

    data: list[PermissionResponse] = Field(..., description="List of permissions")
    meta: dict | None = Field(default=None, description="Pagination metadata")


class PermissionListParams(BaseModel):
    """Query parameters for listing permissions."""

    resource: str | None = Field(default=None, description="Filter by resource")
    service: str | None = Field(default=None, description="Filter by service")
    page: int | None = Field(default=1, ge=1, description="Page number")
    per_page: int | None = Field(default=100, ge=1, le=500, description="Items per page")
