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

class TicketComment extends Model
{
    protected $fillable = ['ticket_id','user_id','client_user_id','body','is_internal'];
    protected $casts    = ['is_internal'=>'boolean'];

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

    public function getAuthorNameAttribute(): string
    {
        if ($this->user) return $this->user->name;
        if ($this->clientUser) return $this->clientUser->name;
        return 'System';
    }
}
