<?php

namespace CliqThemes\ORM\Entities;

use CliqThemes\ORM\Model;

/**
 * ORM model representing the wp_comments table.
 */
class Comment extends Model
{
    protected string $table = 'comments';

    protected string $primaryKey = 'comment_ID';

    protected array $fillable = [
        'comment_post_ID',
        'comment_author',
        'comment_author_email',
        'comment_author_url',
        'comment_author_IP',
        'comment_date',
        'comment_date_gmt',
        'comment_content',
        'comment_karma',
        'comment_approved',
        'comment_agent',
        'comment_type',
        'comment_parent',
        'user_id',
    ];

    protected bool $timestamps = false;

    /**
     * Relationship to the post the comment belongs to.
     */
    public function post()
    {
        return $this->belongsTo(Post::class, 'comment_post_ID', 'ID');
    }

    /**
     * Relationship to the user that authored the comment.
     */
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'ID');
    }

    /**
     * Relationship to comment meta rows.
     */
    public function meta()
    {
        return $this->hasMany(CommentMeta::class, 'comment_id', 'comment_ID');
    }
}

