<?php

namespace App\Http\Controllers\Owner\Location;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Owner\c_Admin_Session;
use App\Http\Controllers\Owner\Location\Dto\LocationUpdateDTO;
use App\Http\Helpers\ResponseBuilder;
use App\Modules\DefinedService\Location\Application\Update\UpdateLocationQuery;
use App\Modules\DefinedService\Location\Application\Update\UpdateLocationResponse;
use App\Modules\Shared\Domain\Bus\Query\QueryBus;
use App\Modules\Shared\Validator\Infraestructure\LaravelDTOGenerator;
use Illuminate\Http\Request;

class LocationUpdateController extends Controller
{

    private string $domain = 'Location';

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

    public function __invoke(Request $request)
    {
        /** @var LocationUpdateDTO $dto */
        $dto = $this->dtoGenerator->generate($request->all(), $this->domain, LocationUpdateDTO::class);
        $adminSession = c_Admin_Session::check($request);
        $this->queryBus->ask(new UpdateLocationQuery(
            $dto->Id_Location,
            $dto->Location_Name,
            $dto->Location_Abrv ?? '',
            $dto->Location_Latitude ?? '',
            $dto->Location_Longitude ?? '',
            // $dto->Location_Version ?? 1,
            1,
            $dto->Location_Status ?? 2,
            $adminSession['Id_Admin']
        ));

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