<?php

namespace Gisplus\Package\Crm\Requests;

use App\Rules\ExistRule;
use Illuminate\Support\Facades\Request;
use App\Rules\UpdateUniqueRule;
use Illuminate\Foundation\Http\FormRequest;

class TaskRequest 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()
    {
        $current_path = url()->current();

        if ($current_path === url('taskcommit')) {
            $validation = $this->getValidationList();
            return $validation;
        }
        else if (Request::is('taskupdate')) {
            $validation = $this->getValidationList();


            $validation['task'] = ['required', new ExistRule('tasks', 'id')];



            return $validation;
        }
    }

    public function getValidationList()
    {
        $validation = [

            'assign_to'         => 'required',
            'date'              =>  'required|date|date_format:Y-m-d',
            'title'             =>  'required|min:0|max:100',
            'description'       =>  'nullable|min:0|max:255',
            'status'            =>  'nullable|in:New Contacted,Contacted,Pending',
            'added_by'          =>  'nullable'


        ];

        return $validation;
    }
}
