<?php

namespace Modules\Manage\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Modules\Manage\Enmus\MiniprogramType;

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

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
     */
    public function rules(): array
    {
        return [
            'name'=> 'required|max:50',
            'play_name'=> 'required|max:100',
            'company'=> 'required|max:255',
            'type'=> [
                'required',
                Rule::in( array_map( fn($item)=>$item->value(),MiniprogramType::cases())),
            ],
            'appsecret'=>'required|min:30|max:64',
            'appid'=>'required|min:18|max:32',
            'status'=>'in:0,1',
            'pay_merchant_id' => "Integer|gt:0"
        ];
    }


    public function messages(): array
    {
        return [
            'name.required'=>'小程序名称必填',
            'appid.min'=>'appid太短',
            'appid.max'=>'appid过长',
            'appsecret.min'=>'appsecret太短',
            'appsecret.max'=>'appsecret过长',
            "pay_merchant_id" => "支付配置不正确",
        ];
    }
}


