<?php

namespace Modules\Product\Http\Requests\discount;

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

class Update extends FormRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'id_product'          => 'required|integer',
            'discount_percentage' => 'integer',
            'discount_nominal'    => 'integer',
            'discount_start'      => 'date|date_format:"Y-m-d"',
            'discount_end'        => 'date|date_format:"Y-m-d"|after_or_equal:discount_start',
            'discount_time_start' => 'date|date_format:"H:i:s"',
            'discount_time_end'   => 'date|date_format:"H:i:s"|after:discount_time_start',
            'discount_days'       => '',
            'id_product_discount' => 'required|integer'
        ];
    }

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