<?php

declare(strict_types=1);

namespace ImovelZapAi\Conversations\Infrastructure\Persistence\Eloquent;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;
use ImovelZapAi\Shared\Infrastructure\Persistence\Concerns\BelongsToTenant;
use ImovelZapAi\Shared\Infrastructure\Persistence\Concerns\HasUuidPrimaryKey;

class ConversationSummaryModel extends Model
{
    use BelongsToTenant;
    use HasUuidPrimaryKey;

    protected $table = 'conversation_summaries';

    protected $fillable = [
        'tenant_id',
        'contact_id',
        'conversation_id',
        'body',
        'structured',
    ];

    protected function casts(): array
    {
        return [
            'structured' => 'array',
        ];
    }

    public function contact(): BelongsTo
    {
        return $this->belongsTo(ContactModel::class, 'contact_id');
    }

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

    public function handoff(): HasOne
    {
        return $this->hasOne(HumanHandoffModel::class, 'conversation_summary_id');
    }
}
