<?php

namespace Rvsitebuilder\Wysiwyg\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class FormUpdateRequest extends FormRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
                'form_owner_id' => 'required',
                'form_mail_content' => 'required',
                'form_field_data' => 'required',
                'form_design_data' => 'required',
                'action_type' => 'required',
                'external_url' => 'required',
                'send_to_user' => 'required',
                'subject' => 'required',
                'sender_email' => 'required',
                'sender_name' => 'required',
                'reply_to_email' => 'required',
                'send_to_admin' => 'required',
        ];
    }

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

    public function messages()
    {
        //TODO language system
        return [
                'form_owner_id.required' => __('wysiwyg::blog.validate.FormStore.form_owner_id.required'),
                'form_mail_content.required' => __('wysiwyg::blog.validate.FormStore.form_mail_content.required'),
                'form_field_data.required' => __('wysiwyg::blog.validate.FormStore.form_field_data.required'),
                'form_design_data.required' => __('wysiwyg::blog.validate.FormStore.form_design_data.required'),
                'action_type.required' => __('wysiwyg::blog.validate.FormStore.action_type.required'),
                'external_url.required' => __('wysiwyg::blog.validate.FormStore.external_url.required'),
                'send_to_user.required' => __('wysiwyg::blog.validate.FormStore.send_to_user.required'),
                'subject.required' => __('wysiwyg::blog.validate.FormStore.subject.required'),
                'sender_email.required' => __('wysiwyg::blog.validate.FormStore.sender_email.required'),
                'sender_name.required' => __('wysiwyg::blog.validate.FormStore.sender_name.required'),
                'reply_to_email.required' => __('wysiwyg::blog.validate.FormStore.reply_to_email.required'),
                'send_to_admin.required' => __('wysiwyg::blog.validate.FormStore.send_to_admin.required'),
        ];
    }

    public function sanitize()
    {
        //TODO Define santize for model ให้ไปดูเพิ่มที่ https://laravel.com/docs/5.5/helpers#available-methods
        return [
                'form_owner_id' => 'clean',
                'form_mail_content' => 'clean',
                'form_field_data' => 'clean',
                'form_design_data' => 'clean',
                'action_type' => 'clean',
                'external_url' => 'clean',
                'send_to_user' => 'clean',
                'subject' => 'clean',
                'sender_email' => 'clean',
                'sender_name' => 'clean',
                'reply_to_email' => 'clean',
                'send_to_admin' => 'clean',
        ];
    }
}
