<?php

namespace App\Models;

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

// ══════════════════════════════════════════════════════════════════
//  InPractice — ForumReplyRating Model
//  Table: forum_reply_ratings
//
//  One rating per member per reply (enforced by unique constraint).
//  Pattern mirrors SolutionRating exactly.
//
//  avg_rating and ratings_count are cached on ForumReply —
//  never computed with aggregates on page load.
// ══════════════════════════════════════════════════════════════════

class ForumReplyRating extends Model
{
    public $timestamps = false;

    const UPDATED_AT = null;

    protected $table = 'forum_reply_ratings';

    protected $fillable = [
        'forum_reply_id',
        'user_id',
        'rating',
    ];

    protected $casts = [
        'rating'     => 'integer',
        'created_at' => 'datetime',
    ];

    // ── Relationships ──────────────────────────────────────────

    public function reply(): BelongsTo
    {
        return $this->belongsTo(ForumReply::class, 'forum_reply_id');
    }

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