<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class PostHashtag extends Model
{
    public $timestamps = false;

    protected $table = 'post_hashtags';

    protected $fillable = ['post_id', 'user_id', 'tag', 'created_at'];

    // Store tag always lowercase for consistency
    public function setTagAttribute(string $value): void
    {
        $this->attributes['tag'] = mb_strtolower($value);
    }

    public function post(): BelongsTo
    {
        return $this->belongsTo(Post::class);
    }

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }
}
