<?php

namespace App\Http\Controllers\Owner\OfficesBriefing;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Owner\OfficesBriefing\Dto\OfficesBriefingListDTO;
use App\Http\Helpers\ResponseBuilder;
use App\Modules\DefinedService\OfficesBriefing\Application\List\ListOfficesBriefingQuery;
use App\Modules\DefinedService\OfficesBriefing\Application\OfficesBriefingResponses;
use App\Modules\Shared\Domain\Bus\Query\QueryBus;
use App\Modules\Shared\Validator\Infraestructure\LaravelDTOGenerator;
use Illuminate\Http\Request;

class OfficesBriefingListController extends Controller
{
    private $domain;

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

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

        /** @var OfficesBriefingResponses $response **/
        $response = $this->queryBus->ask(new ListOfficesBriefingQuery(
            $dto->BriefingOffice_Name,
            $Action
        ));

        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"  => '',
            ]
        );
    }
}
