59 lines
2.0 KiB
PHP
59 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Application\Reports;
|
|
|
|
use App\Application\Reports\DTO\GenerateReportResult;
|
|
use App\Infrastructure\Reports\Services\AutoFillReportPayloadBuilder;
|
|
use App\Infrastructure\Reports\Services\ReportSaveOrchestrator;
|
|
use App\Models\Department;
|
|
use App\Models\Report;
|
|
use App\Models\User;
|
|
use App\Services\DateRange;
|
|
|
|
final readonly class ReportSavePathService
|
|
{
|
|
public function __construct(
|
|
private ReportFlowDecider $reportFlowDecider,
|
|
private ReportInputFactory $reportInputFactory,
|
|
private GenerateReportUseCase $generateReportUseCase,
|
|
private ReportSaveOrchestrator $reportSaveOrchestrator,
|
|
private AutoFillReportPayloadBuilder $autoFillReportPayloadBuilder,
|
|
) {}
|
|
|
|
public function usesNewArchitecture(string $reportType = 'daily'): bool
|
|
{
|
|
return $this->reportFlowDecider->shouldUseNewArchitecture($reportType);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $validated
|
|
*/
|
|
public function saveManual(User $actor, array $validated, string $reportType = 'daily'): GenerateReportResult|Report
|
|
{
|
|
if (! $this->usesNewArchitecture($reportType)) {
|
|
return $this->reportSaveOrchestrator->storeReport($validated, $actor, false);
|
|
}
|
|
|
|
return $this->generateReportUseCase->handle(
|
|
$this->reportInputFactory->forManualSave($actor, $validated, $reportType)
|
|
);
|
|
}
|
|
|
|
public function saveAutoFill(
|
|
User $scopedUser,
|
|
Department $department,
|
|
DateRange $dateRange,
|
|
string $reportType = 'daily',
|
|
): GenerateReportResult|Report {
|
|
if (! $this->usesNewArchitecture($reportType)) {
|
|
$payload = $this->autoFillReportPayloadBuilder->build($scopedUser, $department, $dateRange);
|
|
|
|
return $this->reportSaveOrchestrator->storeReport($payload, $scopedUser, true);
|
|
}
|
|
|
|
return $this->generateReportUseCase->handle(
|
|
$this->reportInputFactory->forAutoFill($scopedUser, $department, $dateRange, $reportType)
|
|
);
|
|
}
|
|
}
|