<?php

namespace LaraBB\Category\Models;

use App\Traits\Uuid;
use App\Traits\Who;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use LaraBB\Forum\Models\Forum;
use Str;

/**
 * Class Category
 *
 * @property int $id
 * @property string $uuid
 * @property Carbon $created_at
 * @property string $created_uuid
 * @property Carbon $updated_at
 * @property string $updated_uuid
 * @property string $title
 * @property string $slug
 * @property Collection $forums
 *
 * @package LaraBB\Category\Models
 */
class Category extends Model
{
    use Uuid;
    use Who;

    /**
     * @var string
     */
    protected $table = 'categories';
    /**
     * @var string
     */
    protected $primaryKey = 'uuid';

    /**
     * @return HasMany
     */
    public function forums(): HasMany
    {
        return $this->hasMany(Forum::class, 'category_uuid', 'uuid');
    }

    /**
     * @param $value
     */
    public function setSlugAttribute($value)
    {
        $this->attributes['slug'] = Str::slug($value);
    }
}
