<?php

namespace App\Models;

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

class LexaChatHistory extends Model
{
    protected $table = 'lexa_chat_history';

    protected $fillable = [
        'user_id',
        'conversation_id',
        'role',
        'message',
        'model',
        'tokens_input',
        'tokens_output',
        'metadata',
    ];

    protected function casts(): array
    {
        return [
            'tokens_input' => 'integer',
            'tokens_output' => 'integer',
            'metadata' => 'array',
            'created_at' => 'datetime',
            'updated_at' => 'datetime',
        ];
    }

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

    public function conversation(): BelongsTo
    {
        return $this->belongsTo(LexaConversation::class, 'conversation_id', 'conversation_key');
    }
}

