<?php
if (!defined('ABSPATH')) {
    exit;
}

class Manfiet_Expense_Role_Permissions {
    public static function add_roles() {
        if (!get_role('expense_manager')) {
            add_role('expense_manager', __('Expense Manager', 'manfi-expense-tracker'), [
                'manage_expenses' => true,
                'read' => true,
            ]);
        }

        // Force add manage_expenses capability to administrator - this is critical
        $admin_role = get_role('administrator');
        if ($admin_role) {
            $admin_role->add_cap('manage_expenses');
        }
    }

    public static function remove_roles() {
        remove_role('expense_manager');

        $role = get_role('administrator');
        if ($role && $role->has_cap('manage_expenses')) {
            $role->remove_cap('manage_expenses');
        }
    }
}
