<?php

namespace App\Http\Controllers\Owner\WebPage;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Owner\c_Admin_Session;
use App\Http\Controllers\Owner\WebPage\Dto\WebPageUpdateDTO;
use App\Http\Helpers\ResponseBuilder;
use App\Modules\Image\Domain\ImageThumbnailData;
use App\Modules\Image\Infraestructure\BasicConfigImageStorage;
use App\Modules\Leads\WebPage\Application\Index\IndexWebPageQuery;
use App\Modules\Leads\WebPage\Application\Update\UpdateWebPageQuery;
use App\Modules\Leads\WebPage\Application\WebPageResponse;
use App\Modules\Shared\Domain\Bus\Query\QueryBus;
use App\Modules\Shared\Validator\Infraestructure\LaravelDTOGenerator;
use Illuminate\Http\Request;

class WebPageUpdateController extends Controller
{

    private string $domain = 'WebPage';

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

    public function __invoke(Request $request)
    {
        /** @var WebPageUpdateDTO $dto */
        $dto = $this->dtoGenerator->generate($request->all(), $this->domain, WebPageUpdateDTO::class);
        $adminSession = c_Admin_Session::check($request);
        
        
        /** @var WebPageResponse $response*/
        $response = $this->queryBus->ask(new IndexWebPageQuery($request->input('Id_WebPage')));

        $this->queryBus->ask(new UpdateWebPageQuery(
            $dto->Id_WebPage,
            $dto->WebPage_Name,
            $dto->WebPage_Domain,
            $dto->WebPage_Description,
            $dto->WebPage_Version,
            $dto->WebPage_Status,
            $dto->Id_Language,
            $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"     => ''
        ]);
    }
}
