<?php

namespace App\Http\Controllers\PaxInformationLink\PaxInformationRoomPassenger;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Owner\c_Admin_Session;
use App\Http\Controllers\PaxInformationLink\PaxInformationRoomPassenger\Dto\PaxInformationRoomPassengerInsertDTO;
use App\Http\Helpers\ResponseBuilder;
use App\Modules\PaxInformationRoomPassenger\Application\Insert\InsertPaxInformationRoomPassengerQuery;
use App\Modules\PaxInformationRoomPassenger\Application\Insert\InsertPaxInformationRoomPassengerResponse;
use App\Modules\PaxInformationRoomPassenger\Domain\PaxInformationRoomPassengerStatus;
use App\Modules\Shared\Domain\Bus\Query\QueryBus;
use App\Modules\Shared\Validator\Infraestructure\LaravelDTOGenerator;
use Illuminate\Http\Request;

class PaxInformationRoomPassengerInsertController extends Controller
{

    private string $domain = 'PaxInformationRoomPassenger';

    public function __construct(
        private QueryBus $queryBus,
        private LaravelDTOGenerator $dtoGenerator
    ) {}

    public function __invoke(Request $request)
    {
        /** @var PaxInformationRoomPassengerInsertDTO $dto */
        $dto = $this->dtoGenerator->generate($request->all(), $this->domain, PaxInformationRoomPassengerInsertDTO::class);
        /** @var InsertPaxInformationRoomPassengerResponse $response */
        $response = $this->queryBus->ask(new InsertPaxInformationRoomPassengerQuery(
            date('Y-m-d H:i:s'),
            date('Y-m-d H:i:s'),
            PaxInformationRoomPassengerStatus::ACTIVE,
            $dto->Id_PaxInformationRoom,
            $dto->Id_Passenger,
            0
        ));

        return ResponseBuilder::Response([
            "Response_Status"           => 200,
            "Response_Code"             => 200,
            "Response_Data"             => ['id' => $response->id()],
            "Response_Domain"           => $this->domain,
            "Response_Message"          => 'Pasajero de habitación agregado con éxito',
            "Response_Error_Message"    => '',
            "Response_Error_Reason"     => ''
        ]);
    }
}
