<?php


namespace App\Http\Requests\Supplier;

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

class SupplierRequest extends FormRequest
{
    use RequestApiFormValidation;

    protected $storeApiRules = [
        'name' => 'required',
        'contact_man' => 'required',
        'phone' => 'required|numeric',
        'invoice_title' => 'required',
        'bank' => 'required',
        'bank_account' => 'required',
        'opening_bank' => 'required',
        'material_id'=> 'required'
    ];
    protected $storeApiMessage = [
        'name.required' => '供应商能为必填项',
        'contact_man.required' => '联系人为必填项',
        'phone.required' => '联系电话为必填项',
        'phone.numeric' => '联系电话必须由数字组成',
        'invoice_title.required' => '发票抬头为必填项',
        'bank.required' =>  '账户银行为必填项',
        'bank_account.required' => '收款账号为必填项',
        'opening_bank.required' => '开户银行为必填项',
        'material_id.required' => '耗材类型为必选项',
    ];

    protected $updateApiRules = [
        'name' => 'required',
        'contact_man' => 'required',
        'phone' => 'required|numeric',
        'invoice_title' => 'required',
        'bank' => 'required',
        'bank_account' => 'required',
        'opening_bank' => 'required',
        'material_id'=> 'required'

    ];
    protected $updateMessage = [
        'name.required' => '供应商能为必填项',
        'contact_man.required' => '联系人为必填项',
        'phone.required' => '联系电话为必填项',
        'phone.numeric' => '联系电话必须由数字组成',
        'invoice_title.required' => '发票抬头为必填项',
        'bank.required' =>  '账户银行为必填项',
        'bank_account.required' => '收款账号为必填项',
        'opening_bank.required' => '开户银行必填项',
        'material_id.required' => '耗材类型为必选项',
    ];


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


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

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