46 lines
1.6 KiB
PHP
46 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Enums\DiscordAllowedMentionType;
|
|
use App\Enums\NotificationChannel;
|
|
use App\Enums\NotificationEventType;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class StoreProjectNotificationActionRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return $this->user() !== null;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$messageTemplateRules = $this->input('channel') === NotificationChannel::Discord->value
|
|
? ['required', 'string', 'max:2000']
|
|
: ['nullable', 'string', 'max:2000'];
|
|
|
|
return [
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'event_type' => ['required', 'string', Rule::in(NotificationEventType::values())],
|
|
'channel' => ['required', 'string', Rule::in(NotificationChannel::values())],
|
|
'channel_configuration' => ['nullable', 'array'],
|
|
'channel_configuration.allowed_mentions' => ['nullable', 'array'],
|
|
'channel_configuration.allowed_mentions.*' => ['nullable', 'string', Rule::in(DiscordAllowedMentionType::values())],
|
|
'enabled' => ['required', 'boolean'],
|
|
'delivery_url' => ['required', 'string', 'max:2048', 'url'],
|
|
'message_template' => $messageTemplateRules,
|
|
];
|
|
}
|
|
}
|