<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

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

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules  = [
            'the_id' => 'required|numeric|min:0',
            'prefix_id' => 'required|numeric',
            'name_ar' => 'required|max:225',
            'name_en' => 'required|max:225',
            'position_id' => 'required|numeric',
            'sector_id' => 'required|numeric',
            'extension_id' => 'required|numeric',
            'mobile' => 'required',
            'telephone' => 'required',
            'fax' => 'required',
            'address' => 'required',
            'email' => 'required|email',
            'website' => 'required',
            'moto_text' => 'required',
            'location' => 'sometimes',
            'password' => 'sometimes',
        ];

        if($this->type == 'manager') { $rules['employees'] = 'required'; }

        if($this->method() == 'POST') { $rules['main_image'] = 'mimes:jpeg,jpg,png,gif|required|max:10000'; }
        if($this->method() == 'PUT') { $rules['main_image'] = 'mimes:jpeg,jpg,png,gif|sometimes|max:10000'; }

        return $rules;

    }
}
