<?php

namespace Modules\RedirectComplex\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exceptions\HttpResponseException;

class UpdateRequest extends FormRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' 				=>'required',
            'outlet' 			=>'nullable',
            'product' 			=>'nullable',
            'promo'				=>'nullable',
            'outlet_type' 		=>'nullable',
            'type' 				=>'nullable',
            'promo_type' 		=>'nullable',
            'promo_reference' 	=>'nullable',
            'payment_method' 	=>'nullable',
            'use_product' 		=>'nullable',
            'transaction_type' 	=>'nullable',
            'id_redirect_complex_reference'	=>'required'
        ];
    }

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    protected function failedValidation(Validator $validator)
    {
        throw new HttpResponseException(response()->json(['status' => 'fail', 'messages'  => $validator->errors()->all()], 200));
    }

    protected function validationData()
    {
        return $this->json()->all();
    }
}
