<?php
declare (strict_types = 1);

namespace app\index\model;

use app\common\model\SysBannerBaseModel;
use think\model\concern\SoftDelete;

/**
 * 横幅（分类）模型
 * @mixin \think\Model
 */
class SysBannerModel extends SysBannerBaseModel
{
    // 启用软删除
    use SoftDelete;
    // 软删除字段
    protected $deleteTime = 'deleted_at';

    // 关联横幅数据项
    public function items()
    {
        return $this->hasMany(SysBannerItemModel::class, 'banner_id', 'id');
    }

    // 所属平台范围查询
    public function scopeAtPlatform($query, string|array $platform)
    {
        if (is_array($platform)) {
            $query->whereIn('at_platform', $platform);
            return;
        }
        $query->where('at_platform', '=', $platform);
    }

    // 唯一标识范围查询
    public function scopeUniqueLabel($query, string|array $unique_label)
    {
        if (is_array($unique_label)) {
            $query->whereIn('unique_label', $unique_label);
            return;
        }
        $query->where('unique_label', '=', $unique_label);
    }

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

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

    // 启用状态范围查询
    public function scopeEnabled($query, bool $enabled = true)
    {
        $query->where('status', '=', (int)$enabled);
    }
}
