buckets/app/Http/Resources/BucketResource.php

35 lines
1.3 KiB
PHP
Raw Normal View History

2025-12-31 00:02:54 +01:00
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class BucketResource extends JsonResource
{
/**
* All amounts in storage units (cents for currency, basis points for percentages).
* Frontend handles conversion to display units.
*/
2025-12-31 00:02:54 +01:00
public function toArray(Request $request): array
{
return [
'id' => $this->uuid,
2025-12-31 00:02:54 +01:00
'name' => $this->name,
'type' => $this->type,
'type_label' => $this->type->getLabel(),
2025-12-31 00:02:54 +01:00
'priority' => $this->priority,
'sort_order' => $this->sort_order,
'allocation_type' => $this->allocation_type,
'allocation_value' => $this->allocation_value,
'allocation_type_label' => $this->getAllocationTypeLabel(),
'buffer_multiplier' => (float) $this->buffer_multiplier,
'effective_capacity' => $this->hasFiniteCapacity() ? $this->getEffectiveCapacity() : null,
'starting_amount' => $this->starting_amount,
2025-12-31 00:02:54 +01:00
'current_balance' => $this->getCurrentBalance(),
'has_available_space' => $this->hasAvailableSpace(),
'available_space' => $this->hasFiniteCapacity() ? $this->getAvailableSpace() : null,
2025-12-31 00:02:54 +01:00
];
}
}