Files
onboard/app/Application/Reports/ReportSavePathService.php

57 lines
1.8 KiB
PHP

<?php
namespace App\Application\Reports;
use App\Application\Reports\DTO\GenerateReportResult;
use App\Models\Department;
use App\Models\Report;
use App\Models\User;
use App\Services\DateRange;
use App\Services\ReportService;
final readonly class ReportSavePathService
{
public function __construct(
private ReportFlowDecider $reportFlowDecider,
private ReportInputFactory $reportInputFactory,
private GenerateReportUseCase $generateReportUseCase,
private ReportService $reportService,
) {}
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->reportService->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->reportService->buildAutoFillReportPayload($scopedUser, $department, $dateRange);
return $this->reportService->storeReport($payload, $scopedUser, true);
}
return $this->generateReportUseCase->handle(
$this->reportInputFactory->forAutoFill($scopedUser, $department, $dateRange, $reportType)
);
}
}