<?php

namespace App\Http\Controllers\Owner\CommercialInvoice;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Owner\CommercialInvoice\Dto\CommercialInvoiceListDTO;
use App\Http\Helpers\ResponseBuilder;
use App\Modules\CommercialInvoice\Application\CommercialInvoiceResponses;
use App\Modules\CommercialInvoice\Application\List\ListCommercialInvoiceQuery;
use App\Modules\Shared\Domain\Bus\Query\QueryBus;
use App\Modules\Shared\Validator\Infraestructure\LaravelDTOGenerator;
use Illuminate\Http\Request;

class CommercialInvoiceListController extends Controller
{
    private $domain;

    public function __construct(
        private QueryBus $queryBus,
        private LaravelDTOGenerator $dtoGenerator
    ) {
        $this->domain = "CommercialInvoice";
    }

    public function __invoke(Request $request, $Action)
    {
        /** @var CommercialInvoiceListDTO $dto */
        $dto = $this->dtoGenerator->generate($request->all(), $this->domain, CommercialInvoiceListDTO::class);
        /** @var CommercialInvoiceResponses $response */
        $response = $this->queryBus->ask(new ListCommercialInvoiceQuery(
            $dto->Id_Booking,
            $Action,
            $dto->Id_BookingUpgradePassenger,
            $dto->Id_BookingExtraPassenger
        ));

        return ResponseBuilder::Response([
            "Response_Status"           => 200,
            "Response_Code"             => 200,
            "Response_Data"             => $response->data(),
            "Response_Domain"           => $this->domain,
            "Response_Message"          => 'Listado con éxito',
            "Response_Error_Message"    => '',
            "Response_Error_Reason"     => '',
        ]);
    }
}
