<?php

namespace App\Http\Controllers\Owner\TypeDefinedService;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Owner\c_Admin_Session;
use App\Http\Controllers\Owner\TypeDefinedService\Dto\TypeDefinedServiceUpdateDTO;
use App\Http\Helpers\ResponseBuilder;
use App\Modules\DefinedService\TypeDefinedService\Application\Update\UpdateTypeDefinedServiceQuery;
use App\Modules\Shared\Domain\Bus\Query\QueryBus;
use App\Modules\Shared\Validator\Infraestructure\LaravelDTOGenerator;
use Illuminate\Http\Request;

class TypeDefinedServiceUpdateController extends Controller
{

    private string $domain = 'TypeDefinedService';

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

    public function __invoke(Request $request)
    {
        /** @var TypeDefinedServiceUpdateDTO $dto */
        $dto = $this->dtoGenerator->generate($request->all(), $this->domain, TypeDefinedServiceUpdateDTO::class);
        $adminSession = c_Admin_Session::check($request);
        $this->queryBus->ask(new UpdateTypeDefinedServiceQuery(
            $dto->Id_TypeDefinedService,
            $dto->TypeDefinedService_Name,
            $dto->TypeDefinedService_Code,
            $dto->TypeDefinedService_Version,
            $dto->TypeDefinedService_Status,
            $adminSession['Id_Admin']
        ));

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