<?php

namespace App\Models;

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

class TicketReply extends Model
{
    protected $fillable = [
        'ticket_id', 'whmcs_reply_id', 'author_type', 'is_internal_note',
        'staff_user_id', 'whmcs_admin_username', 'author_name',
        'body', 'attachments', 'whmcs_attachment_ids',
        'ai_provider', 'ai_model', 'ai_prompt_id', 'ai_confidence', 'ai_cost_usd',
        'sent_at',
    ];

    protected $casts = [
        'attachments'          => 'array',
        'whmcs_attachment_ids' => 'array',
        'is_internal_note'     => 'boolean',
        'sent_at'              => 'datetime',
        'ai_confidence'        => 'decimal:3',
        'ai_cost_usd'          => 'decimal:4',
    ];

    public function ticket(): BelongsTo    { return $this->belongsTo(Ticket::class); }
    public function staff(): BelongsTo     { return $this->belongsTo(User::class, 'staff_user_id'); }
}
