<?php


namespace App\Http\Requests\DischargeTask;

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


class DischargeTaskRequest extends FormRequest
{
    use RequestApiFormValidation;

    protected $deleteApiRules =[
        'id' => 'required'
    ];
    protected $deleteApiMessage =[
        'id.required' => '参数错误'
    ];
    protected $storeApiRules =[
        'owner_id' => 'required',
        'type' => 'required',
        'numbers' => 'required',
        'warehouse_id' => 'required',
        'income_unit' => 'required',
        'income_amount' => 'required',
        'income_unit_price' => 'required',
    ];
    protected $storeApiMessage =[
        'owner_id.required' => '货物为必选项',
        'type.required' => '任务类型为必选项',
        'numbers.required' => '入库单号为必填项',
        'warehouse_id.required' => '仓库未必须选项',
        'income_amount.required' => '数量为必填项',
        'income_unit.required' => '单位为必选项',
        'income_unit_price.required'=> '单价为必填项',

    ];
    protected $updateApiRules =[
        'owner_id' => 'required',
        'type' => 'required',
        'numbers' => 'required',
        'warehouse_id' => 'required',
        'income_unit' => 'required',
        'income_amount' => 'required',
        'income_unit_price' => 'required',
    ];
    protected $updateApiMessage =[
        'owner_id.required' => '货物为必选项',
        'type.required' => '任务类型为必选项',
        'numbers.required' => '入库单号为必填项',
        'warehouse_id.required' => '仓库未必须选项',
        'income_amount.required' => '数量为必填项',
        'income_unit.required' => '单位为必选项',
        'income_unit_price.required'=> '单价为必填项',
    ];
    protected $updateTaskFacilitatorApiRules =[
        'id' => 'required',
        'facilitator_id' => 'required',
        'expenditure_amount' => 'required',
        'expenditure_unit' => 'required',
        'expenditure_unit_price' => 'required',
    ];
    protected  $updateTaskFacilitatorApiMessage =[
        'id.required'=>'未选中卸货任务',
        'facilitator_id.required' => '服务商为必选项',
        'expenditure_amount.required' => '数量为必填项',
        'expenditure_unit.required' => '单位为必选项',
        'expenditure_unit_price.required' => '单价为必填项',
    ];

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

    public function rules(): array
    {
        $currentRoute = Route::getCurrentRoute();
        $routeName = $currentRoute->getName();
        switch ($routeName){
            case 'discharge.deleteApi':
                return $this->deleteApiRules;
            case 'discharge.storeApi':
                return $this->storeApiRules;
            case 'discharge.updateApi':
                return $this->updateApiRules;
            case 'discharge.updateTaskFacilitatorApi':
                return $this->updateTaskFacilitatorApiRules;
            default :
                return [];
        }
    }

    public function messages(): array
    {
        $currentRoute = Route::getCurrentRoute();
        $routeName = $currentRoute->getName();
        switch ($routeName){
            case 'discharge.deleteApi':
                return $this->deleteApiMessage;
            case 'discharge.storeApi':
                return $this->storeApiMessage;
            case 'discharge.updateApi':
                return $this->updateApiMessage;
            case 'discharge.updateTaskFacilitatorApi':
                return $this->updateTaskFacilitatorApiMessage;
            default :
                return [];
        }
    }

}
