2025-12-31 00:02:54 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Actions;
|
|
|
|
|
|
2026-01-01 03:18:40 +01:00
|
|
|
use App\Enums\BucketAllocationTypeEnum;
|
2025-12-31 00:02:54 +01:00
|
|
|
use App\Models\Scenario;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
|
|
readonly class CreateScenarioAction
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
|
|
|
|
private CreateBucketAction $createBucketAction
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
public function execute(array $data): Scenario
|
|
|
|
|
{
|
|
|
|
|
return DB::transaction(function () use ($data) {
|
|
|
|
|
$scenario = Scenario::create($data);
|
|
|
|
|
$this->createDefaultBuckets($scenario);
|
|
|
|
|
|
|
|
|
|
return $scenario;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function createDefaultBuckets(Scenario $scenario): void
|
|
|
|
|
{
|
2026-01-01 03:18:40 +01:00
|
|
|
$this->createBucketAction->execute($scenario, 'Monthly Expenses', BucketAllocationTypeEnum::FIXED_LIMIT, 0, 1);
|
|
|
|
|
$this->createBucketAction->execute($scenario, 'Emergency Fund', BucketAllocationTypeEnum::FIXED_LIMIT, 0, 2);
|
|
|
|
|
$this->createBucketAction->execute($scenario, 'Investments', BucketAllocationTypeEnum::UNLIMITED, null, 3);
|
2025-12-31 00:02:54 +01:00
|
|
|
}
|
|
|
|
|
}
|