<?php

namespace App\Modules\Dashboard\Requests;

use App\Support\NotificationCategory;
use Illuminate\Foundation\Http\FormRequest;

class NotificationIndexRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user() !== null;
    }

    /**
     * @return array<string, array<int, string>>
     */
    public function rules(): array
    {
        return [
            'type' => ['nullable', 'string', 'in:all,'.implode(',', NotificationCategory::all())],
        ];
    }

    public function filterCategory(): ?string
    {
        $t = $this->input('type', 'all');

        return $t === 'all' ? null : (string) $t;
    }
}
