<?php

namespace App\Policies;

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

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

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

    public function decide(User $user, Expense $expense): bool
    {
        return $user->can(PermissionName::EXPENSES_APPROVE->value)
            && $this->branchAccess->canAccessBranch($user, (int) $expense->branch_id);
    }
}
