Files
KanbanGit/app/Http/Requests/StoreProjectNotificationActionRequest.php
T
2026-04-24 20:02:22 +00:00

87 lines
2.4 KiB
PHP

<?php
namespace App\Http\Requests;
use App\Enums\NotificationChannel;
use App\Enums\NotificationEventType;
use App\Http\Requests\Concerns\InteractsWithNotificationFilters;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Validator;
class StoreProjectNotificationActionRequest extends FormRequest
{
use InteractsWithNotificationFilters;
/**
* 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
{
return [
'name' => ['required', 'string', 'max:255'],
'event_type' => ['required', 'string', Rule::in($this->eventTypes())],
'channel' => ['required', 'string', Rule::in($this->channels())],
'enabled' => ['required', 'boolean'],
'delivery_url' => ['required', 'string', 'max:2048', 'url'],
'message_template' => $this->messageTemplateRules(),
...$this->notificationFilterRules(),
];
}
protected function prepareForValidation(): void
{
$this->prepareNotificationFiltersForValidation();
}
public function withValidator(Validator $validator): void
{
$this->withNotificationFilterValidator($validator);
}
/**
* @return array<int, string>
*/
private function channels(): array
{
return array_map(
static fn (NotificationChannel $channel): string => $channel->value,
NotificationChannel::cases(),
);
}
/**
* @return array<int, string>
*/
private function eventTypes(): array
{
return array_map(
static fn (NotificationEventType $eventType): string => $eventType->value,
NotificationEventType::cases(),
);
}
/**
* @return array<int, ValidationRule|string>
*/
private function messageTemplateRules(): array
{
if ($this->input('channel') === NotificationChannel::Discord->value) {
return ['required', 'string', 'max:2000'];
}
return ['nullable', 'string', 'max:2000'];
}
}