<?php

declare(strict_types=1);

namespace ImovelZapAi\Conversations\Infrastructure\Persistence\Eloquent;

use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use ImovelZapAi\Conversations\Domain\Enums\ReplySuggestionStatus;
use ImovelZapAi\Shared\Infrastructure\Persistence\Concerns\BelongsToTenant;
use ImovelZapAi\Shared\Infrastructure\Persistence\Concerns\HasUuidPrimaryKey;

class ReplySuggestionModel extends Model
{
    use BelongsToTenant;
    use HasUuidPrimaryKey;

    protected $table = 'reply_suggestions';

    protected $fillable = [
        'tenant_id',
        'contact_id',
        'conversation_id',
        'created_by',
        'suggested_body',
        'generated_by',
        'status',
        'sent_body',
        'estimated_time_saved_seconds',
        'resolved_at',
    ];

    protected function casts(): array
    {
        return [
            'status' => ReplySuggestionStatus::class,
            'estimated_time_saved_seconds' => 'integer',
            'resolved_at' => 'datetime',
        ];
    }

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

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

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