<?php

declare(strict_types=1);

namespace ImovelZapAi\Conversations\Application\Services;

use ImovelZapAi\Conversations\Infrastructure\Persistence\Eloquent\ContactModel;

final class WhatsAppLinkBuilder
{
    public function forContact(ContactModel $contact): ?string
    {
        $digits = preg_replace('/\D+/', '', (string) ($contact->wa_id ?: $contact->phone ?: ''));

        if ($digits === null || $digits === '') {
            return null;
        }

        return 'https://wa.me/'.$digits;
    }
}
