<?php
/**
 *
 * @file:PlayPageUrlRequest.php
 * @Date: 2023/7/6
 * @Time: 18:18
 */


namespace Modules\WechatPlatform\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\DB;

class PlayPageUrlRequest extends FormRequest
{
    /**
     * rules
     *
     * @return array
     */
    public function rules(): array
    {
        return [
            'video_id' => [
                'required',
                'Integer',
                "gt:0",
                function ($attribute, $value, $fail) {
                    $has = DB::table('videos')->where('id', $value)->first();
                    if (empty($has)) {
                        $fail("短剧不不正确");
                        exit();
                    }
                    if ($has->shelf_type != 2){
                        $fail("短剧未上架");
                    }
                }
            ],
            'sequence' => [
                'required',
                'Integer',
                "gt:0"
            ],
        ];
    }

    /**
     * messages
     *
     * @return string[]
     */
    public function messages(): array
    {
        return [
            'video_id.required' => '请选择短剧',
            'sequence.required' => '请选择剧集',
            'sequence' => '剧集不正确',
        ];
    }

}
