<?php

namespace Modules\WhatsApp\Entities\Services;

use Modules\WhatsApp\Entities\WaConversation;
use Modules\WhatsApp\Entities\WaMessage;

/**
 * Single entry point for processing an inbound message: run the deterministic
 * workflow (auto-replies) first, then the AI if the workflow didn't stop.
 * Used by the queued job (real bridge/webhook) and inline by the simulator.
 */
class InboundPipeline
{
    public function process(WaMessage $inbound, WaConversation $conversation): void
    {
        $continueToAi = (new WorkflowService())->handleInbound($inbound, $conversation);
        if ($continueToAi) {
            (new WaAiResponder())->respond($inbound, $conversation);
        }
    }
}
