"""
Schema Pydantic per permessi granulari casella (Fase 1-A).
"""

import uuid
from datetime import datetime

from pydantic import BaseModel


class PermissionGrantRequest(BaseModel):
    can_read: bool = True
    can_send: bool = False
    can_manage: bool = False


class PermissionResponse(BaseModel):
    id: uuid.UUID
    tenant_id: uuid.UUID
    user_id: uuid.UUID
    mailbox_id: uuid.UUID
    can_read: bool
    can_send: bool
    can_manage: bool
    granted_by: uuid.UUID | None
    granted_at: datetime

    model_config = {"from_attributes": True}


class UserMailboxPermissionResponse(BaseModel):
    """Vista utente: caselle accessibili con relativi permessi."""
    mailbox_id: uuid.UUID
    mailbox_email: str
    mailbox_display_name: str | None
    can_read: bool
    can_send: bool
    can_manage: bool


class MailboxUserPermissionResponse(BaseModel):
    """Vista casella: utenti con accesso."""
    user_id: uuid.UUID
    user_email: str
    user_full_name: str
    user_role: str
    can_read: bool
    can_send: bool
    can_manage: bool
    granted_at: datetime
