<?php
/**
 * ${CARET}
 * @file:CpRequest.php
 * @Created by gnitif
 * @Date: 2023/3/22
 * @Time: 17:06
 */


namespace Modules\System\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Modules\System\Models\NoticeTypes;


class NoticeRequest extends FormRequest
{

    /**
     * rules
     *
     * @return array
     */
    public function rules(): array
    {
        return [
            'title' => "required|string",
            'notice_type_id' => [
                'required',
                function ($attribute, $value, $fail) {
                    $has = NoticeTypes::where('is_deleted', 0)->where('id', $value)->value('id');
                    if (empty($has)) {
                        $fail("所选分类不存在！");
                    }
                }
            ],
            'type'=> "required|Integer|in:1,2,3", // 通知人群 1全部 2，指定人,3指定角色
            'is_popup' => "required|Integer|in:0,1",
            'content' => "required|string",
        ];
    }

    /**
     * messages
     *
     * @return string[]
     */
    public function messages(): array
    {
        return [
            'title' => '通知标题必填',
            'notice_type_id.required' => '通知分类必填',
            'type.required' => '通知展示人类型必填',
            'type' => '通知展示人类型不正确',
            'is_popup' => '展示类型不正确',
            'content' => '通知内容必填',
            'notice_obj' => "通知对象必填",
        ];
    }
}
