<?php

namespace App\Models;

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

class ForumLike extends Model
{
    protected $fillable = [
        'user_id',
        'post_id',
        'type',
    ];

    protected $casts = [
        'type' => 'string',
    ];

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

    public function post(): BelongsTo
    {
        return $this->belongsTo(ForumPost::class, 'post_id');
    }

    public function scopeLike($query)
    {
        return $query->where('type', 'like');
    }

    public function scopeDislike($query)
    {
        return $query->where('type', 'dislike');
    }
}
