<?php

namespace App\Models\Forums;

use App\Models\Lab;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class ForumChannel extends Model
{

    use SoftDeletes;
    /**
     * Don't auto-apply mass assignment protection.
     *
     * @var array
     */
    protected $guarded = [];

    // I like to explicitly define tables
    protected $table = 'forum_channels';

    // also fillable
    protected $fillable = [
        'name',
        'user_id',
        'is_announcement_forum',
        'public',
        'lab_id'
    ];

    // the channel(s)/topics this thread belongs to
//    public function threads()
//    {
//        return $this->belongsToMany('App\Models\Forums\ForumThread', 'forum_channels_forum_threads', 'forum_channels_id', 'forum_threads_id' );
//    }

    public function threads()
    {
        return $this->hasMany('App\Models\Forums\ForumThread', 'forum_channels_id', 'id');
    }

    public function user()
    {
        return $this->hasOne('App\Models\Auth\User', 'id', 'user_id');
    }

    public function lab()
    {
        return $this->hasOne('App\Models\Lab', 'id', 'lab_id');
    }

    // Get threads *not* in a lab
    public function scopeNotInLabForum($query)
    {
        return $query->whereNull('lab_id');
    }

}
