"""Workspace and project roles and permissions."""

from __future__ import annotations

from enum import Enum


class WorkspaceRole(Enum):
    """Roles within a workspace.

    Define the permission levels for workspace membership:
    - OWNER: Full control, can delete workspace
    - ADMIN: Can manage members, settings
    - MEMBER: Can create/edit meetings
    - VIEWER: Read-only access
    """

    OWNER = "owner"
    ADMIN = "admin"
    MEMBER = "member"
    VIEWER = "viewer"

    def can_write(self) -> bool:
        """Check if this role allows write operations."""
        return self in (WorkspaceRole.OWNER, WorkspaceRole.ADMIN, WorkspaceRole.MEMBER)

    def can_admin(self) -> bool:
        """Check if this role allows administrative operations."""
        return self in (WorkspaceRole.OWNER, WorkspaceRole.ADMIN)

    def can_delete_workspace(self) -> bool:
        """Check if this role allows workspace deletion."""
        return self == WorkspaceRole.OWNER


class ProjectRole(Enum):
    """Role within a project.

    Define the permission levels for project membership:
    - VIEWER: Read meetings, artifacts, run Q&A
    - EDITOR: + Create/edit meetings, upload artifacts
    - ADMIN: + Manage members, settings, rules

    Note: Workspace OWNER/ADMIN always have ProjectRole.ADMIN
    for all projects in that workspace (resolved at service layer).
    """

    VIEWER = "viewer"
    EDITOR = "editor"
    ADMIN = "admin"

    def can_read(self) -> bool:
        """Check if this role allows read operations.

        Returns:
            True for all roles (all can read).
        """
        return True

    def can_write(self) -> bool:
        """Check if this role allows write operations.

        Returns:
            True for EDITOR and ADMIN roles.
        """
        return self in (ProjectRole.EDITOR, ProjectRole.ADMIN)

    def can_admin(self) -> bool:
        """Check if this role allows administrative operations.

        Returns:
            True for ADMIN role only.
        """
        return self == ProjectRole.ADMIN
