<?php


namespace App\Http\Requests\Configuration;

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

class ConfigurationRequest extends FormRequest
{
    use RequestApiFormValidation;

    protected $storeApiRules =[
        'name' => 'required',
        'value' => 'required',
        'description' => 'required',
    ];
    protected $storeApiMessage = [
        'name.required' => '系统配置名称为必填项',
        'value.required' => '系统配置值为必填项',
        'description.required' => '系统配置值描述为必填项',
    ];

    protected $updateApiRules = [
        'name' => 'required',
        'value' => 'required',
        'description' =>  'required'
    ];

    protected $updateApiMessage = [
        'name.required' => '系统配置名称为必填项',
        'value.required' => '系统配置值为必填项',
        'description.required' => '系统配置值描述为必填项',
    ];

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


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