<?php


namespace App\Http\Requests\OwnerMaterial;

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

class OwnerMaterialRequest extends FormRequest
{
    use RequestApiFormValidation;

    use RequestApiFormValidation;

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


    protected $storeApiRules = [
        'owner_id' => 'required',       // 货主
        'material_id' => 'required',    // 耗材
        'size' => 'required',    // size
        'material_code' => 'required',  // 耗材编码
    ];
    protected $storeApiMessage = [
        'owner_id.required' => '货主为必选项',
        'material_id.required' => '耗材为必选项',
        'size.required' => '尺寸为必填项',
        'material_code.required' => '耗材编码为必填项',
    ];

    protected $updateApiRules = [
        'owner_id' => 'required',       // 货主
        'material_id' => 'required',    // 耗材
        'size' => 'required',    // size
        'material_code' => 'required',  // 耗材编码
    ];
    protected $updateApiMessage = [
        'owner_id.required' => '货主为必选项',
        'material_id.required' => '耗材为必选项',
        'size.required' => '尺寸为必填项',
        'material_code.required' => '耗材编码为必填项',
    ];

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

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

}
