<?php

namespace App\Http\Requests\RoomCategories;

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

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

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

    /**
     * @return array
     */
    public function rules(): array
    {
        return [
            'room_parent' => ['nullable','numeric'],
            'slug' => ['nullable', 'string', 'max:200'],
            'room_category_az' => ['nullable','string','max:200'],
            'room_category_ru' => ['nullable','string','max:200'],
            'room_category_en' => ['nullable','string','max:200'],
            'option' => ['nullable','string','max:200'],
            'show_in_main' => ['sometimes','boolean'],
            'image' => ['nullable', 'file', 'image' ,'mimes:jpeg,png,jpg,gif,webp,svg,heic']
        ];
    }
}
