<?php

namespace App\Http\Requests\MenuCategories;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Str;

class MenuCategoryUpdateRequest extends FormRequest
{
    /**
     * @return bool
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * @return void
     */
    protected function prepareForValidation(): void
    {
        $this->merge([
            'slug' => Str::slug($this->input('menu_category_az')),
            'menu_parent' => $this->filled('menu_parent') ? $this->input('menu_parent') : null,
            'show_in_main' => $this->has('show_in_main')
        ]);
    }

    /**
     * @return array
     */
    public function rules(): array
    {
        return [
            'menu_parent' => ['nullable','numeric'],
            'slug' => ['nullable', 'string', 'max:200'],
            'position' => ['nullable', 'string', 'max:500'],
            'number' => ['nullable', 'string', 'max:500'],
            'menu_category_az' => ['nullable','string','max:200'],
            'option' => ['nullable','string','max:200'],
            'menu_category_ru' => ['nullable','string','max:200'],
            'menu_category_en' => ['nullable','string','max:200'],
            'show_in_main' => ['sometimes','boolean'],
            'image' => ['nullable', 'file', 'image' ,'mimes:jpeg,png,jpg,gif,webp,svg,heic']
        ];
    }
}
