<?php

namespace Themes\Pro\modunawa\app\Http\Controllers\Shop;

use App\Http\Controllers\Controller;
use App\Services\CallApiService;
use Themes\Pro\modunawa\app\Services\MsqMarketApiService;

class WalletBalanceController extends Controller
{
    private $callApiService;
    private $msqMarketApiService;

    public function __construct(CallApiService $callApiService, MsqMarketApiService $msqMarketApiService)
    {
        $this->callApiService = $callApiService;
        $this->msqMarketApiService = $msqMarketApiService;
    }

    public function index()
    {
        $prepare = $this->msqMarketApiService->prepare('auth');

        if ($this->callApiService->verifyApiError($prepare)) {
            notify()->error($prepare['body'], 'Error', 'bottomRight');
            echo "<script>window.top.location.href = '" . url()->previous() . "'</script>";
            return false;
        }

//        dump($prepare);

        return view('views.shop.checkout.wallet-balance.index', compact('prepare'));
    }

    public function result()
    {
        $result = $this->msqMarketApiService->result(request('request_key'));

        return response()->json($result);
    }
}
