<?php

namespace App\Policies;

use App\Models\RecurringExpense;
use App\Models\User;
use App\Services\BranchAccessService;
use App\Support\Authorization\PermissionName;

class RecurringExpensePolicy
{
    public function __construct(private BranchAccessService $branchAccess) {}

    public function view(User $user, RecurringExpense $recurringExpense): bool
    {
        return $user->can(PermissionName::EXPENSES_VIEW->value)
            && $this->branchAccess->canAccessBranch($user, (int) $recurringExpense->branch_id);
    }

    public function manage(User $user, RecurringExpense $recurringExpense): bool
    {
        return $user->can(PermissionName::EXPENSES_RECURRING_MANAGE->value)
            && $this->branchAccess->canAccessBranch($user, (int) $recurringExpense->branch_id);
    }
}
