<?php

namespace Modules\Advert\Http\Requests;

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

class Iklan extends FormRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'page'      => 'sometimes|required|in:news,product,outlet,contact-us,order-choose-outlet,order-choose-product,order-cart,order-shipment,order-payment,deals,inbox,voucher,history',
            'id_advert' => 'sometimes',
        ];
    }

    public function messages()
    {
        return [
            'page.in' => 'page available = news,product,outlet,contact-us,order-choose-outlet,order-choose-product,order-cart,order-shipment,order-payment,deals,inbox,voucher,history',
        ];
    }

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