<?php


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


class MaterialRequest extends FormRequest
{
    use RequestApiFormValidation;

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

    protected $storeApiRules =[
        'name' => 'required',
        'code' => 'required',
    ];
    protected $storeApiMessage = [
        'name.required' => '耗材类型名称为必填项',
        'code.required' => '编号为必填项'
    ];

    protected $updateApiRules = [
        'name' => 'required',
        'code' => 'required',
        'id' =>  'required'
    ];

    protected $updateApiMessage = [
        'name.required' => '名称不能为空',
        'code.required' => '编号不能为空',
        'id.required' => '未选中耗材类型',
    ];


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