<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Model;

/**
 * Story tag entity for creator stories.
 *
 * @property int    $id
 * @property string $slug
 * @property string $name
 */
class StoryTag extends Model
{
    use HasFactory;

    protected $table = 'story_tags';

    protected $fillable = [
        'slug',
        'name',
    ];

    // ── Relations ────────────────────────────────────────────────────────

    public function stories(): BelongsToMany
    {
        return $this->belongsToMany(Story::class, 'relation_story_tags', 'tag_id', 'story_id');
    }

    // ── Accessors ────────────────────────────────────────────────────────

    public function getUrlAttribute(): string
    {
        return url('/stories/tag/' . $this->slug);
    }
}
