<?php

namespace App\Models;

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

class ProfileComment extends Model
{
    protected $table = 'profile_comments';

    protected $fillable = [
        'profile_user_id',
        'author_user_id',
        'body',
        'is_active',
    ];

    protected $casts = [
        'is_active' => 'boolean',
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
    ];

    /** Profile owner */
    public function profileUser(): BelongsTo
    {
        return $this->belongsTo(User::class, 'profile_user_id');
    }

    /** Comment author */
    public function author(): BelongsTo
    {
        return $this->belongsTo(User::class, 'author_user_id');
    }

    public function authorProfile(): BelongsTo
    {
        return $this->belongsTo(UserProfile::class, 'author_user_id', 'user_id');
    }

    /** Scope: only active (not removed) comments */
    public function scopeActive($query)
    {
        return $query->where('is_active', true);
    }
}
