<?php

namespace Rvsitebuilder\Wysiwyg\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class AddPageRequest extends FormRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'showMenu' => 'required',
            'page_name' => 'required|forbidden_route|unique:core_page',
        ];
    }

    public function authorize()
    {
        return $this->user()->isAdmin();
    }

    public function messages()
    {
        //TODO language system
        return [
                'showMenu.required' => __('wysiwyg::blog.validate.AddPage.showMenu.required'),
                'page_name.required' => __('wysiwyg::blog.validate.AddPage.page_name.required'),
                'page_name.unique' => __('wysiwyg::blog.validate.AddPage.page_name.unique'),
                'page_name.forbidden_route' => __('wysiwyg::blog.validate.AddPage.page_name.forbidden_route'),
        ];
    }

    public function sanitize()
    {
        //TODO Define santize for model ให้ไปดูเพิ่มที่ https://laravel.com/docs/5.5/helpers#available-methods
        return [
            'showMenu' => 'clean',
            'page_name' => 'clean',
        ];
    }
}
