<?php

namespace App\Http\Requests\Tenant;

use App\Enums\GuestNotificationType;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class BroadcastGuestNotificationRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'title' => ['required', 'string', 'max:160'],
            'message' => ['required', 'string', 'max:2000'],
            'type' => ['nullable', 'string', Rule::in(array_map(fn (GuestNotificationType $type) => $type->value, GuestNotificationType::cases()))],
            'audience' => ['nullable', 'string', Rule::in(['all', 'guest'])],
            'guest_identifier' => ['nullable', 'string', 'max:120', 'required_if:audience,guest'],
            'cta' => ['nullable', 'array'],
            'cta.label' => ['required_with:cta.url', 'string', 'max:80'],
            'cta.url' => ['required_with:cta.label', 'string', 'max:2048'],
            'expires_in_minutes' => ['nullable', 'integer', 'between:5,2880'],
            'priority' => ['nullable', 'integer', 'between:0,5'],
        ];
    }
}
