<?php
/**
 *
 * @file:WechatKeywordsRequest.php
 * @Date: 2023/7/5
 * @Time: 15:11
 */


namespace Modules\WechatPlatform\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Modules\User\Http\Controllers\UserTrait;
use Modules\WechatPlatform\Services\WechatKeywordsService;

class WechatKeywordsRequest extends FormRequest
{

    use  UserTrait;
    /**
     * rules
     *
     * @return array
     */
    public function rules(): array
    {
        return [
            'keyword' => "required",
            'type' => [
                "required",
                function ($attribute, $value, $fail) {
                    $types = array_column(WechatKeywordsService::getWechatKeywordType(), 'value');
                    if (!in_array($value, $types)) {
                        $fail("关键词类型不正确！");
                        exit();
                    }
                }
            ],
            'miniprogram_id' => [
                'required',
                'Integer',
                "gt:0",
            ],
            "content" =>   "required|array",
        ];
    }


    /**
     * messages
     *
     * @return string[]
     */
    public function messages(): array
    {
        return [
            'type.required' => '关键词类型必须填写',
            'keyword.required' => '关键词必须填写',
            "miniprogram_id.required" => "小程序必须填写",
            "content.required" => "内容必须填写",
            "content.array" => "内容格式不正确",
        ];
    }
}
