<?php

namespace Modules\Product\Http\Requests\Modifier;

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

class CreateRequest extends FormRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'modifier_type'       => 'in:Global,Specific,Global Brand|required',
            'type'                => 'string|required',
            'code'                => 'string|required|unique:product_modifiers,code',
            'text'                => 'string|required',
            'id_brand'            => 'array|nullable|sometimes',
            'id_product_category' => 'array|nullable|sometimes',
            'id_product'          => 'array|nullable|sometimes'
        ];
    }

    /**
     * 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();
    }
}
