<?php

namespace App\Distributor\Repositories;

use App\Models\DistVideoCategory as Model;
use App\Traits\DistSlugTrait;
use Dcat\Admin\Repositories\EloquentRepository;

class DistVideoCategory extends EloquentRepository
{
    use DistSlugTrait;
    /**
     * Model.
     *
     * @var string
     */
    protected $eloquentClass = Model::class;

    // 调用模型方法
    public static function selectOptions(\Closure $closure = null,$root = false)
    {
        if (!$closure) {
            $closure = function ($query) {
                $query = $query->where('dist_id', getDistributorId());
                $query = $query->where('enabled', 1);
                $query =  $query->orderBy('order', 'desc')->orderBy('id', 'desc');
                return $query;
            };
        }

        $selectOptions =  Model::class::selectOptions($closure);
        if ($root == false) {
            unset($selectOptions[0]);
        }
        return $selectOptions;
    }

    public static function findById($id)
    {
        return Model::find($id); // 查找并返回相应的记录
    }
}
