<?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\CreateProformaInvoiceTransactionProcessor;
use App\Http\Resources\BookingResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class CreateProformaInvoiceTransactionLogic extends AbstractControllerLogic
{

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

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

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

    /** @var CreateProformaInvoiceTransactionProcessor */
    private $CreateProformaInvoiceTransactionProcessor;

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


    /**
     * @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->CreateProformaInvoiceTransactionProcessor->execute($booking);

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

}