<?php

namespace App\Http\Controllers\Tenant;

use App\Http\Controllers\Controller;
use App\Models\Customer;
use App\Services\VirtualAccountService;
use Illuminate\Http\RedirectResponse;

class CustomerVirtualAccountController extends Controller
{
    public function store(Customer $customer, VirtualAccountService $accounts): RedirectResponse
    {
        abort_unless(auth()->user()?->hasPermission('customers.manage'), 403);
        abort_unless($customer->isVisibleTo(auth()->user()), 403, 'This member is assigned to another account officer.');

        $result = $accounts->create($customer);

        return back()->with($result['successful'] ? 'status' : 'warning', $result['message']);
    }
}
