Scenario::orderBy('created_at', 'desc')->get() ]); } public function show(Scenario $scenario): Response { $scenario->load(['buckets' => function ($query) { $query->orderedBySortOrder(); }]); return Inertia::render('Scenarios/Show', [ 'scenario' => $scenario, 'buckets' => $scenario->buckets->map(function ($bucket) { return [ 'id' => $bucket->id, 'name' => $bucket->name, 'priority' => $bucket->priority, 'sort_order' => $bucket->sort_order, 'allocation_type' => $bucket->allocation_type, 'allocation_value' => $bucket->allocation_value, 'allocation_type_label' => $bucket->getAllocationTypeLabel(), 'formatted_allocation_value' => $bucket->getFormattedAllocationValue(), 'current_balance' => $bucket->getCurrentBalance(), 'has_available_space' => $bucket->hasAvailableSpace(), 'available_space' => $bucket->getAvailableSpace(), ]; }) ]); } public function create(): Response { return Inertia::render('Scenarios/Create'); } public function store(Request $request): RedirectResponse { $request->validate([ 'name' => 'required|string|max:255', ]); $scenario = Scenario::create([ 'name' => $request->name, ]); // Create default buckets using the action $createBucketAction = new CreateBucketAction(); $createBucketAction->createDefaultBuckets($scenario); return redirect()->route('scenarios.show', $scenario); } public function edit(Scenario $scenario): Response { return Inertia::render('Scenarios/Edit', [ 'scenario' => $scenario ]); } public function update(Request $request, Scenario $scenario): RedirectResponse { $request->validate([ 'name' => 'required|string|max:255', 'description' => 'nullable|string', 'start_date' => 'nullable|date', 'end_date' => 'nullable|date|after_or_equal:start_date', ]); $scenario->update($request->only(['name', 'description', 'start_date', 'end_date'])); return redirect()->route('scenarios.show', $scenario) ->with('success', 'Scenario updated successfully'); } public function destroy(Scenario $scenario): RedirectResponse { $scenario->delete(); return redirect()->route('scenarios.index') ->with('success', 'Scenario deleted successfully'); } }