<?php
declare (strict_types = 1);

namespace app\index\model;

use app\common\model\VideoBaseModel;
use think\Model;
use think\model\concern\SoftDelete;

/**
 * 视频模型
 * @mixin \think\Model
 */
class VideoModel extends VideoBaseModel
{
    // 启用软删除
    use SoftDelete;
    // 软删除字段
    protected $deleteTime = 'deleted_at';

    // 视频名称搜索器
    public function searchNameAttr($query, $value, $data)
    {
        if (is_null($value)) {
            return;
        }
        $query->where('name', 'like', "%{$value}%");
    }

    // 所属语言范围查询
    public function scopeLanguage($query, $language)
    {
        $query->where('language_id', '=', $language);
    }

    // 推荐状态范围查询
    public function scopeRecommend($query, bool $recommend)
    {
        $query->where('recommend', '=', (int)$recommend);
    }

    // 所属分类范围查询
    public function scopeCategory($query, $category)
    {
        if (is_null($category)) {
            return;
        }
        $query->where('category_id', '=', $category);
    }
}
