<commit_before><?php

/*
 * +----------------------------------------------------------------------+
 * |                          ThinkSNS Plus                               |
 * +----------------------------------------------------------------------+
 * | Copyright (c) 2017 <NAME> Technology Co., Ltd.     |
 * +----------------------------------------------------------------------+
 * | This source file is subject to version 2.0 of the Apache license,    |
 * | that is bundled with this package in the file LICENSE, and is        |
 * | available through the world-wide-web at the following url:           |
 * | http://www.apache.org/licenses/LICENSE-2.0.html                      |
 * +----------------------------------------------------------------------+
 * | Author: Slim Kit Group <<EMAIL>>                          |
 * | Homepage: www.thinksns.com                                           |
 * +----------------------------------------------------------------------+
 */

namespace SlimKit\PlusQuestion\API2\Requests;

use Illuminate\Foundation\Http\FormRequest;

class PublishQuestion extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     * @author <NAME> <<EMAIL>>
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     * @author <NAME> <<EMAIL>>
     */
    public function rules(): array
    {
        return [
            'subject' => ['bail', 'required', 'max:50', 'regex:/[?|？]$/is'],
            'body' => 'nullable|string',
            'anonymity' => 'nullable|integer|in:0,1',
            'amount' => 'nullable|integer|max:'.$this->user()->currency->sum,
            'look' => 'nullable|integer|in:0,1',
            'topics' => 'bail|required|array',
            'topics.*.id' => 'bail|required_with:topics|distinct|exists:topics,id',
            'invitations' => 'nullable|array',
            'invitations.*.user' => 'bail|required_with:invitations|distinct|not_in:'.$this->user()->id.'|exists:users,id',
        ];
    }

    /**
     * Get custom messages for validator errors.
     *
     * @return array
     * @author <NAME> <<EMAIL>>
     */
    public function messages(): array
    {
        return [
            'subject.regex' => trans('plus-question::questions.Attribute must end with a question mark'),<commit_msg>fix: (issue zhiyicx/thinksns-plus-android#2135) 修复问题标题只输入一个问号也能发布成功的错误<commit_after><?php

/*
 * +----------------------------------------------------------------------+
 * |                          ThinkSNS Plus                               |
 * +----------------------------------------------------------------------+
 * | Copyright (c) 2017 <NAME>Xiang Technology Co., Ltd.     |
 * +----------------------------------------------------------------------+
 * | This source file is subject to version 2.0 of the Apache license,    |
 * | that is bundled with this package in the file LICENSE, and is        |
 * | available through the world-wide-web at the following url:           |
 * | http://www.apache.org/licenses/LICENSE-2.0.html                      |
 * +----------------------------------------------------------------------+
 * | Author: Slim Kit Group <<EMAIL>>                          |
 * | Homepage: www.thinksns.com                                           |
 * +----------------------------------------------------------------------+
 */

namespace SlimKit\PlusQuestion\API2\Requests;

use Illuminate\Foundation\Http\FormRequest;

class PublishQuestion extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     * @author <NAME> <<EMAIL>>
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     * @author <NAME> <<EMAIL>>
     */
    public function rules(): array
    {
        return [
            'subject' => ['bail', 'required', 'min:2', 'max:50', 'regex:/[?|？]$/is'],
            'body' => 'nullable|string',
            'anonymity' => 'nullable|integer|in:0,1',
            'amount' => 'nullable|integer|max:'.$this->user()->currency->sum,
            'look' => 'nullable|integer|in:0,1',
            'topics' => 'bail|required|array',
            'topics.*.id' => 'bail|required_with:topics|distinct|exists:topics,id',
            'invitations' => 'nullable|array',
            'invitations.*.user' => 'bail|required_with:invitations|distinct|not_in:'.$this->user()->id.'|exists:users,id',
        ];
    }

    /**
     * Get custom messages for validator errors.
     *
     * @return array
     * @author <NAME> <<EMAIL>>
     */
    public function messages(): array
    {
        return [
            'subject.regex' => trans('plus-question::questions.Attribute must end with a question mark'),
{'fraction_non_alphanumeric': 0.2695477386934673, 'fraction_numerical': 0.007035175879396985, 'mean_word_length': 1.310120705663881, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3316560', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1300, 'n_words': 289}