<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Config;

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

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        $maxFacets = Config::get('filter.max_facets');

        return [
            'facets' => ['required', 'array', 'max:' . $maxFacets],
            'facets.*.id' => ['required', 'exists:search_facets,id'],
            'facets.*.position' => ['required', 'integer', 'between:1,' . $maxFacets],
        ];
    }
}
