*/ private const array DISCORD_ALLOWED_MENTION_TYPES = ['everyone', 'roles', 'users']; /** * 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> */ public function rules(): array { return [ 'name' => ['required', 'string', 'max:255'], 'event_type' => ['required', 'string', Rule::in($this->eventTypes())], 'channel' => ['required', 'string', Rule::in($this->channels())], 'channel_configuration' => ['nullable', 'array'], 'channel_configuration.allowed_mentions' => ['nullable', 'array'], 'channel_configuration.allowed_mentions.*' => $this->allowedMentionRules(), 'enabled' => ['required', 'boolean'], 'delivery_url' => ['required', 'string', 'max:2048', 'url'], 'message_template' => $this->messageTemplateRules(), ]; } /** * @return array */ private function channels(): array { return array_map( static fn (NotificationChannel $channel): string => $channel->value, NotificationChannel::cases(), ); } /** * @return array */ private function eventTypes(): array { return array_map( static fn (NotificationEventType $eventType): string => $eventType->value, NotificationEventType::cases(), ); } /** * @return array */ private function messageTemplateRules(): array { if ($this->input('channel') === NotificationChannel::Discord->value) { return ['required', 'string', 'max:2000']; } return ['nullable', 'string', 'max:2000']; } /** * @return array */ private function allowedMentionRules(): array { return [ 'nullable', 'string', Rule::in(self::DISCORD_ALLOWED_MENTION_TYPES), ]; } }