<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Comment extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'post_id', 'user_id', 'parent_id',
        'author_name', 'author_email', 'author_ip',
        'content', 'status', 'likes_count',
    ];

    public function post()     { return $this->belongsTo(Post::class); }
    public function user()     { return $this->belongsTo(User::class); }
    public function parent()   { return $this->belongsTo(Comment::class, 'parent_id'); }
    public function replies()  { return $this->hasMany(Comment::class, 'parent_id'); }

    public function scopeApproved($q) { return $q->where('status', 'approved'); }
    public function scopePending($q)  { return $q->where('status', 'pending'); }
}
