<?php

namespace App\Classes\Modules\Billplzs\ControllersLogic;

use App\Classes\General\Abstracts\AbstractControllerLogic;

use App\Classes\Modules\Billplzs\Services\CreatesBillplzBill;

use ErrorException;
use App\Classes\Exceptions\MalformedRequestException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class CreateBillplzBillLogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Created Billplz Bill',
            'message' => 'You have successfully created a new Bill'
        ];
    }

    /** @var CreatesBillplzBill */
    private $createsBillplzBill;

    /**
     * CreateBookingLogic constructor.
     * @param CreatesBillplzBill $createsBillplzBill
     */
    public function __construct(CreatesBillplzBill $createsBillplzBill)
    {
        $this->createsBillplzBill = $createsBillplzBill;
    }


    /**
     * @param Request $request
     * @return JsonResponse
     * @throws MalformedRequestException
     */
    public function logic(Request $request) : JsonResponse
    {
        $billPlz = $this->createsBillplzBill->execute($request->user()->name, $request->user()->email, $request->input('description'), 200, $request->input('bankName'));

        if(!$billPlz) throw new MalformedRequestException('Unable to get correct response from billplz server.');
        
        return $this->response(['data' => $billPlz]);

    }
}