<?php

namespace App\Policies;

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

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

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

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

    public function capital(User $user, FinancialAccount $account): bool
    {
        return $user->can(PermissionName::ACCOUNTS_CAPITAL->value)
            && $this->branchAccess->canAccessBranch($user, (int) $account->branch_id);
    }

    public function transfer(User $user, FinancialAccount $account): bool
    {
        return $user->can(PermissionName::ACCOUNTS_TRANSFER->value)
            && $this->branchAccess->canAccessBranch($user, (int) $account->branch_id);
    }
}
