<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class KnowledgeBase extends Model
{
    use HasFactory, SoftDeletes;

    /**
     * 可批量赋值的属性
     *
     * @var array<string>
     */
    protected $fillable = [
        'name',
        'description',
        'status',
    ];

    /**
     * 获取关联的终端
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function terminals()
    {
        return $this->belongsToMany(Terminal::class, 'terminal_knowledge_bases')
                    ->withPivot('priority')
                    ->withTimestamps()
                    ->orderBy('priority');
    }
}
