<?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 WalletSendController 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('send_transaction', 'MSQ31704797617c0d30c4bd9f7086a8bc19', request('msqxpAmount'), request('p2upAmount'));
//        $prepare = $this->msqMarketApiService->prepare('send_transaction', 'MSQee87a41f58daafe0e0aaadf0f994b7b9', 1, 1);

        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-send.index', compact('prepare'));
    }

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

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