<?php

namespace App\Modules\DefinedService\BriefingPassenger\Application\Insert;

use App\Modules\DefinedService\BriefingPassenger\Domain\BriefingPassengerDate;
use App\Modules\DefinedService\BriefingPassenger\Domain\BriefingPassengerDateUpdate;
use App\Modules\DefinedService\BriefingPassenger\Domain\BriefingPassengerHotel;
use App\Modules\DefinedService\BriefingPassenger\Domain\BriefingPassengerObservations;
use App\Modules\DefinedService\BriefingPassenger\Domain\BriefingPassengerOther;
use App\Modules\DefinedService\BriefingPassenger\Domain\BriefingPassengerPhone;
use App\Modules\DefinedService\BriefingPassenger\Domain\BriefingPassengerTime;
use App\Modules\DefinedService\BriefingPassenger\Domain\BriefingPassengerType;
use App\Modules\DefinedService\BriefingPassenger\Domain\IdAdmin;
use App\Modules\DefinedService\BriefingPassenger\Domain\IdBriefingPassenger;
use App\Modules\DefinedService\BriefingPassenger\Domain\IdGroup;
use App\Modules\DefinedService\BriefingPassenger\Domain\IdBooking;
use App\Modules\DefinedService\BriefingPassenger\Domain\IdBriefingOffice;
use App\Modules\DefinedService\BriefingPassenger\Domain\IdPassenger;
use App\Modules\Shared\Domain\Bus\Query\QueryHandler;

final class InsertBriefingPassengerQueryHandler implements QueryHandler
{
    public function __construct(private BriefingPassengerInserter $inserter) {}

    public function __invoke(InsertBriefingPassengerQuery $query): InsertBriefingPassengerResponse
    {
        $idBriefingOffice = $query->idBriefingOffice() ?? 0;

        return new InsertBriefingPassengerResponse(($this->inserter)(
            new IdBriefingPassenger(0),
            new BriefingPassengerDate($query->date()),
            new BriefingPassengerDateUpdate($query->dateUpdate()),
            new BriefingPassengerType($query->type()),
            new BriefingPassengerHotel($query->hotel() ?? ''),
            new BriefingPassengerTime($query->time() ?? '00:00:00'),
            new BriefingPassengerPhone($query->phone() ?? ''),
            new BriefingPassengerOther($query->other() ?? ''),
            new BriefingPassengerObservations($query->observations() ?? ''),
            new IdGroup($query->idGroup()),
            new IdBooking($query->idBooking()),
            new IdBriefingOffice($idBriefingOffice), // Pasa 0 si el valor era NULL
            new IdPassenger($query->idPassenger()),
            new IdAdmin($query->idAdmin())
        ));
    }
}
