<?php

namespace App\Domains\AI\Models;

use App\Domains\Tenancy\Models\Tenant;
use App\Models\User;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class AiInteraction extends Model
{
    use HasFactory;
    use HasUuids;

    public $timestamps = false;

    protected $fillable = [
        'tenant_id',
        'user_id',
        'conversation_id',
        'contact_id',
        'lead_id',
        'feature_key',
        'provider_key',
        'model_key',
        'prompt_version',
        'input_context_json',
        'output_json',
        'confidence_score',
        'status',
        'tokens_input',
        'tokens_output',
        'latency_ms',
        'cost_amount',
        'created_at',
    ];

    protected $casts = [
        'input_context_json' => 'array',
        'output_json' => 'array',
        'created_at' => 'datetime',
    ];

    public function tenant(): BelongsTo
    {
        return $this->belongsTo(Tenant::class);
    }

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