<?php

namespace App\Http\Controllers\Owner\{{ module }};

use App\Http\Controllers\Controller;
use App\Http\Controllers\Owner\c_Admin_Session;
use App\Http\Controllers\Owner\{{ module }}\Dto\{{ module }}InsertDTO;
use App\Http\Helpers\ResponseBuilder;
use App\Modules\{{ module }}\Application\Insert\Insert{{ module }}Command;
use App\Modules\{{ module }}\Application\Insert\Insert{{ module }}Response;
use App\Modules\Shared\Domain\Bus\Command\CommandBus;
use App\Modules\Shared\Validator\Infraestructure\LaravelDTOGenerator;
use Illuminate\Http\Request;

final class {{ module }}InsertController extends Controller
{
    private $domain;

    public function __construct(
        private CommandBus $commandBus,
        private LaravelDTOGenerator $dtoGenerator,
    ) {
        $this->domain = '{{ module }}';
    }

    public function __invoke(Request $request)
    {
        /** @var {{ module }}InsertDTO $dto */
        $dto = $this->dtoGenerator->generate($request->all(), $this->domain, {{ module }}InsertDTO::class);
        $adminSession = c_Admin_Session::check($request);

        /** @var Insert{{ module }}Response $response */
        $response = $this->commandBus->dispatch(new Insert{{ module }}Command(
{{ cmdArgs }}
        ));

        return ResponseBuilder::generate(
            ['id' => $response->id()],
            Responses{{ module }}::RESPONSE_INSERT,
            $this->domain
        );
    }
}
