<?php

namespace App\Models;

use App\Models\Scopes\ModelScopes;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Validator;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Comment extends Model
{
    use ModelScopes;
    use HasFactory;

    protected $table = 'comments';

    protected $casts = [
        'created_at' => 'datetime:M d, Y h:m a',
    ];

    protected $fillable = [
        'user_id',
        'ticket_id',
        'comment',
    ];

    public function ticket()
    {
        return $this->belongsTo(Ticket::class);
    }

    public function users()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }

    public function sub_comments()
    {
        return $this->hasMany(Comment::class, 'parent_id', 'id')->with('users');
    }
}
