<?php

namespace App\Classes\Modules\Bookings\ControllersLogic;

use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Bookings\Services\FetchesBooking;
use App\Classes\Modules\Bookings\Standards\Rules\CanFetchBooking;
use App\Classes\Modules\Transactions\Processors\CreateBankingInvoiceTransactionProcessor;
use App\Http\Resources\BookingResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class CreateBankingInvoiceTransactionLogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Create Banking Invoice Transaction',
            'message' => 'You have successfully create banking invoice transaction'
        ];
    }

    /** @var CanFetchBooking */
    private $canFetchBooking;

    /** @var FetchesBooking */
    private $fetchesBooking;

    /** @var CreateBankingInvoiceTransactionProcessor */
    private $createBankingInvoiceTransactionProcessor;

    /**
     * CreateBankingInvoiceTransactionLogic constructor.
     * @param CanFetchBooking $canFetchBooking
     * @param FetchesBooking $fetchesBooking
     * @param CreateBankingInvoiceTransactionProcessor $createBankingInvoiceTransactionProcessor
     */
    public function __construct(
        CanFetchBooking $canFetchBooking,
        FetchesBooking $fetchesBooking,
        CreateBankingInvoiceTransactionProcessor $createBankingInvoiceTransactionProcessor
    )
    {
        $this->canFetchBooking = $canFetchBooking;
        $this->fetchesBooking = $fetchesBooking;
        $this->createBankingInvoiceTransactionProcessor = $createBankingInvoiceTransactionProcessor;
    }


    /**
     * @param Request $request
     * @return JsonResponse
     * @throws \App\Classes\Exceptions\AccessForbiddenException
     * @throws \App\Classes\Exceptions\MalformedRequestException
     * @throws \App\Classes\Exceptions\RequestValidationException
     */
    public function logic(Request $request) : JsonResponse
    {
        // $this->canFetchBooking->passes();

        $booking = $this->fetchesBooking->execute(['id' => $request->route('id')]);

        $this->createBankingInvoiceTransactionProcessor->execute($booking);

        return $this->resourceResponse(new BookingResource($booking));
    }

}
