from dataclasses import dataclass
from typing import Optional, override

from ai.backend.manager.actions.action import BaseActionResult
from ai.backend.manager.data.permission.role import (
    UserRoleAssignmentData,
    UserRoleAssignmentInput,
)
from ai.backend.manager.services.permission_contoller.actions.base import RoleAction


@dataclass
class AssignRoleAction(RoleAction):
    input: UserRoleAssignmentInput

    @override
    def entity_id(self) -> Optional[str]:
        return str(self.input.user_id)

    @override
    @classmethod
    def operation_type(cls) -> str:
        return "assign"


@dataclass
class AssignRoleActionResult(BaseActionResult):
    success: bool
    data: Optional[UserRoleAssignmentData]

    @override
    def entity_id(self) -> Optional[str]:
        return None
