<?php
namespace App\Http\Requests\Api;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;

class StoreEventsRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return Auth::user()->role ;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'city' => 'required|max:45',
            "category_id"    => "array",
            "category_id.*"  => "exists:categories,id",
            'title' => 'max:90|required',
            'description' => 'max:1000|required',
            'price' => 'regex:/^\d{0,9}(\.\d{1,2})?$/',
            'start_date' => 'nullable|date_format:'.config('app.date_format').' H:i:s',
            'end_date' => 'nullable|date_format:'.config('app.date_format').' H:i:s',
            'street' => 'required',
            'image' => 'nullable|mimes:png,jpg,jpeg,gif',
            'organization' => 'max:90',
            'event_dates.*.start_date' => 'nullable|date_format:'.config('app.date_format').' H:i:s',
            'event_dates.*.end_date' => 'nullable|date_format:'.config('app.date_format').' H:i:s',
            'location_x_latitude' => 'regex:/^\d*(\.\d{1,15})?$/',
            'location_x_longitude' => 'regex:/^\d*(\.\d{1,15})?$/'
        ];
    }

    public function messages()
    {
        return [
            'price.regex' => 'Это поле должно содержать только цифры формата 9 целочисленных и 2 значения после точки',
        ];
    }
}
