"""Schemas for role permissions management."""

from __future__ import annotations

from typing import Dict

from pydantic import BaseModel, ConfigDict, Field

from backend.constants.role_features import ROLE_FEATURES
from backend.constants.roles import UserRole


class RoleFeatureSchema(BaseModel):
    """Feature metadata visible in the UI."""

    key: str
    label: str


class RolePermissionsResponse(BaseModel):
    """Payload returned when listing role permissions."""

    model_config = ConfigDict(protected_namespaces=())

    features: list[RoleFeatureSchema]
    permissions: Dict[UserRole, Dict[str, bool]]


class RolePermissionsUpdateRequest(BaseModel):
    """Payload for updating role permissions."""

    model_config = ConfigDict(protected_namespaces=())

    permissions: Dict[UserRole, Dict[str, bool]] = Field(
        ...,
        description="Map of role -> {feature_key: allowed}",
    )

    @staticmethod
    def build_feature_list() -> list[RoleFeatureSchema]:
        return [RoleFeatureSchema(**feature) for feature in ROLE_FEATURES]







