42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Enums;
|
|
|
|
enum BucketAllocationType: string
|
|
{
|
|
case FIXED_LIMIT = 'fixed_limit';
|
|
case PERCENTAGE = 'percentage';
|
|
case UNLIMITED = 'unlimited';
|
|
|
|
public function getLabel(): string
|
|
{
|
|
return match($this) {
|
|
self::FIXED_LIMIT => 'Fixed Limit',
|
|
self::PERCENTAGE => 'Percentage',
|
|
self::UNLIMITED => 'Unlimited',
|
|
};
|
|
}
|
|
|
|
public static function values(): array
|
|
{
|
|
return array_column(self::cases(), 'value');
|
|
}
|
|
|
|
public function getAllocationValueRules(): array
|
|
{
|
|
return match($this) {
|
|
self::FIXED_LIMIT => ['required', 'numeric', 'min:0'],
|
|
self::PERCENTAGE => ['required', 'numeric', 'min:0.01', 'max:100'],
|
|
self::UNLIMITED => ['nullable'],
|
|
};
|
|
}
|
|
|
|
public function formatValue(?float $value): string
|
|
{
|
|
return match($this) {
|
|
self::FIXED_LIMIT => '$' . number_format($value ?? 0, 2),
|
|
self::PERCENTAGE => number_format($value ?? 0, 2) . '%',
|
|
self::UNLIMITED => 'All remaining',
|
|
};
|
|
}
|
|
}
|