You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.1 KiB
64 lines
2.1 KiB
<?php
|
|
|
|
namespace App\Domains\Identity\Enums;
|
|
|
|
use App\UI\Enums\Concerns\InteractsWithLabels;
|
|
use App\UI\Enums\Contracts\HasLabel;
|
|
use App\UI\Enums\Contracts\HasSchema;
|
|
use App\UI\Enums\InputType;
|
|
use App\UI\Support\Schemas\InputSchema;
|
|
use App\UI\Support\Schemas\InputSchemaField;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
enum UserSettingKey: string implements HasLabel, HasSchema
|
|
{
|
|
use InteractsWithLabels;
|
|
|
|
case NOTIFICATION = 'notification';
|
|
case LANGUAGE = 'language';
|
|
case TIMEZONE = 'timezone';
|
|
|
|
public function schema(): InputSchema
|
|
{
|
|
$options = match ($this) {
|
|
self::LANGUAGE => [
|
|
'en' => __('domains/identity/enum.user_setting_key.options.language.en'),
|
|
'id' => __('domains/identity/enum.user_setting_key.options.language.id'),
|
|
],
|
|
self::TIMEZONE => [
|
|
'UTC' => __('domains/identity/enum.user_setting_key.options.timezone.UTC'),
|
|
'Asia/Jakarta' => __('domains/identity/enum.user_setting_key.options.timezone.Asia/Jakarta'),
|
|
'Asia/Makassar' => __('domains/identity/enum.user_setting_key.options.timezone.Asia/Makassar'),
|
|
'Asia/Jayapura' => __('domains/identity/enum.user_setting_key.options.timezone.Asia/Jayapura'),
|
|
],
|
|
self::NOTIFICATION => [
|
|
1 => __('domains/identity/enum.user_setting_key.options.notification.on'),
|
|
0 => __('domains/identity/enum.user_setting_key.options.notification.off'),
|
|
],
|
|
};
|
|
|
|
$default = match ($this) {
|
|
self::NOTIFICATION => 0,
|
|
self::LANGUAGE => 'en',
|
|
self::TIMEZONE => 'UTC',
|
|
};
|
|
|
|
return InputSchema::make()
|
|
->key($this->value)
|
|
->label($this->label())
|
|
->type(InputType::SELECT)
|
|
->rules(['required', Rule::in(array_keys($options))])
|
|
->default($default)
|
|
->options($options);
|
|
}
|
|
|
|
public function getSchema(): InputSchemaField
|
|
{
|
|
return $this->schema()->getSchema();
|
|
}
|
|
|
|
public function default(): mixed
|
|
{
|
|
return $this->getSchema()->default;
|
|
}
|
|
}
|
|
|