<?php

namespace App\Http\Controllers\Owner\Group;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Owner\Group\Dto\GroupControllerResponses;
use App\Http\Controllers\Owner\Group\Dto\GroupCalendarPassengerListDTO;
use App\Http\Helpers\ResponseBuilder;
use App\Modules\Group\Application\CalendarListPassenger\CalendarListPassengerQuery;
use App\Modules\Group\Application\CalendarListPassenger\CalendarListPassengerQueryResponse;
use App\Modules\Shared\Domain\Bus\Query\QueryBus;
use App\Modules\Shared\Validator\Infraestructure\LaravelDTOGenerator;
use Illuminate\Http\Request;

class GroupCalendarPassengerListController extends Controller
{

    private $domain;

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

    public function __invoke(Request $request, $Action)
    {
        /** @var GroupCalendarPassengerListDTO $dto */
        $dto = $this->dtoGenerator->generate($request->all(), $this->domain, GroupCalendarPassengerListDTO::class);

        /** @var CalendarListPassengerQueryResponse $response */
        $response = $this->queryBus->ask(new CalendarListPassengerQuery(
            $Action,
            $dto->DateStart,
            $dto->OnlyTransfer
        ));

        return ResponseBuilder::Response(ResponseBuilder::buildSelectResponse(
            $response->data(),
            GroupControllerResponses::GROUP_CALENDAR_PASSENGER_LIST,
            $this->domain
        ));
    }
}
