<?php

namespace App\Http\Controllers\Owner\Report\Booking;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Owner\Report\Booking\Dto\ReportBookingBySellerDTO;
use Illuminate\Http\Request;
use App\Http\Helpers\ResponseBuilder;
use App\Modules\Report\Booking\Application\BySellerMonthly\ReportBySellerMonthlyBookingQuery;
use App\Modules\Report\Booking\Application\BySellerMonthly\ReportBySellerMonthlyBookingResponse;
use App\Modules\Shared\Domain\Bus\Query\QueryBus;
use App\Modules\Shared\Domain\Transaction;
use App\Modules\Shared\Validator\Infraestructure\LaravelDTOGenerator;

class ReportBookingBySellerMonthlyController extends Controller
{
    private $domain;

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

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

        // $this->transaction->begin();

        /** @var ReportBySellerMonthlyBookingResponse $response */
        $response = $this->queryBus->ask(new ReportBySellerMonthlyBookingQuery(
            $dto->DateStart,
            $dto->DateEnd,
            $dto->GroupBy,
            $dto->ShowBy,
            $dto->Admin
        ));

        // $this->transaction->commit();
        return ResponseBuilder::Response(ResponseBuilder::buildSelectResponse($response->data(), '', $this->domain));
    }
}
