<?php


namespace App\Http\Requests\DischargeTask;

use App\Traits\RequestApiFormValidation;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Route;

class FacilitatorRequest extends FormRequest
{
    use RequestApiFormValidation;

    protected $deleteApiRules = [
        'id' => 'required'
    ];

    protected $deleteApiMessage = [
        'id.required' => "没有对应的服务商"
    ];

    protected $storeApiRules = [
        'name' => 'required|min:2'
    ];

    protected $storeApiMessage = [
        'id.required' => "服务商名称不能为空",
        'name.min' => '服务商名称长度不能小于2'
    ];

    protected $updateApiMessage = [
        'name.required' => '服务商名称不能为空',
        'name.min' => '服务商名称长度不能小于2'
    ];

    protected $updateApiRules = [
        'name.' => 'required|min:2'
    ];


    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        $routeName = Route::currentRouteName();
        switch ($routeName) {
            case 'facilitator.storeApi':
                return $this->storeApiRules;
            case 'facilitator.updateApi':
                return $this->updateApiRules;
            case 'facilitator.destroyApi':
                return $this->deleteApiRules;
            default :
                return [];
        }
    }

    public function massage(): array
    {
        $routeName = Route::currentRouteName();
        switch ($routeName) {
            case 'facilitator.storeApi':
                return $this->storeApiMessage;
            case 'facilitator.updateApi':
                return $this->updateApiMessage;
            case 'facilitator.destroyApi':
                return $this->deleteApiMessage;
            default :
                return [];
        }
    }
}
