<?php
namespace EasyChat\Library\Support;







class ChatAssignmentPolicy {
    public function capabilities(array $actor): array {
        $active = (int)($actor['status'] ?? 0) === 1;
        $can_manage_others = $active
            && (
                (string)($actor['role'] ?? '') === 'admin'
                || (int)($actor['permission_manage_chat_assignments'] ?? 0) === 1
            );

        return [
            'can_assign_self' => $active,
            'can_unassign_self' => $active,
            'can_manage_others' => $can_manage_others,
        ];
    }

    public function canChangeTarget(array $actor, int $actor_manager_id, int $target_manager_id): bool {
        $capabilities = $this->capabilities($actor);
        if ($actor_manager_id <= 0 || $target_manager_id <= 0) {
            return false;
        }
        if ($target_manager_id === $actor_manager_id) {
            return !empty($capabilities['can_assign_self']);
        }
        return !empty($capabilities['can_manage_others']);
    }
}
