<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class GoodsSkuRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return false;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'id' => ['sometimes', 'required', 'integer', 'exists:goods_skus,id'],
            'goods_id' => ['sometimes', 'required', 'integer', 'exists:goods,id'],
            'title' => ['sometimes', 'required', 'string', 'max:191'],
            'sku_code' => ['sometimes', 'required', 'distinct', 'alpha_dash', 'max:32'],
            'status' => ['sometimes', 'required', 'integer', Rule::in([0, 1, 2])],
            'num' => ['sometimes', 'required', 'integer'],
            'cost' => ['sometimes', 'required', 'numeric'],
            'reference_price' => [
                'sometimes',
                'numeric',
                'gt:0'
            ],
            'reserve' => [
                'sometimes',
                'integer',
            ],
            'loss_num' => [
                'sometimes',
                'integer',
            ],
            'arrived_today_num' => [
                'sometimes',
                'integer',
            ],
            'yesterday_num' => [
                'sometimes',
                'integer',
            ],
            'two_days_ago_num' => [
                'sometimes',
                'integer',
            ],
            'inventory' => [
                'sometimes',
                'integer',
            ],
        ];
    }

    public function arrayRules($arrayName)
    {
        $arrayRules = [];
        $rules = $this->rules();
        foreach ($rules as $key => $val) {
            $arrayRules[$arrayName . $key] = $val;
        }

        return $arrayRules;
    }
}
