<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class StoreTaskRequest extends Request
{
    /**
     * 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 = [];
        
        // Only validate formatted time fields for repair tasks
        if ($this->input('type') === 'repair') {
            $rules['formatedAttendedTime'] = ['nullable', 'regex:/^(\d+[dhm]\s?)*\d*[dhm]?$/i'];
            $rules['formatedUnattendedTime'] = ['nullable', 'regex:/^(\d+[dhm]\s?)*\d*[dhm]?$/i'];
        }
        
        // Validate formatted time spent for support tasks
        if ($this->input('type') === 'support') {
            $rules['formatedTimeSpent'] = ['nullable', 'regex:/^(\d+[dhm]\s?)*\d*[dhm]?$/i'];
        }
        
        return $rules;
    }
}
