<?php

namespace App\Classes\Jobs\Commands\V2;

use App\Classes\Modules\Transactions\Processors\CreateInvoiceTransactionV2Processor;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

class CreateInvoiceTransactionV2CommandJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /** @var object */
    private $booking;

    /**
     * CreateInvoiceTransactionV2CommandJob constructor.
     * @param object $booking
     */
    public function __construct($booking)
    {
        $this->booking = $booking;
    }

    public function handle()
    {
        Log::info(Carbon::now() . ': Start job - Creating invoice for single booking.');
        $start   = new Carbon();

        (App()->make(CreateInvoiceTransactionV2Processor::class))->execute($this->booking);

        $end = new Carbon();
        $elapsedTime = $start->diff($end)->format('%H:%I:%S');
        Log::info(Carbon::now() . ': End job - Creating invoice for single booking. ElapsedTime: ' . $elapsedTime . '.');
    }

}
