<?php
require('include/functions.php');

$msg_faq_no_hamza = "الاسئله الشائعه";
$msg_prices = "أسعار الكورسات";

echo "Testing Match...\n";
$flows = sb_flows_get();
// Manual Match Check
foreach ($flows as $flow) {
    if (isset($flow['steps'][0][0][0])) {
        $trigger_step = $flow['steps'][0][0][0];
        $user_messages_trigger = sb_isset($trigger_step, 'message', []);
        
        if (!empty($user_messages_trigger)) {
            if (!is_array($user_messages_trigger)) $user_messages_trigger = [$user_messages_trigger];
            foreach ($user_messages_trigger as $msg_item) {
                $msg_trigger = is_array($msg_item) ? sb_isset($msg_item, 'message') : $msg_item;
                $msg_trigger = strtolower(trim($msg_trigger));
                
                if (strtolower(trim($msg_faq_no_hamza)) == $msg_trigger) {
                    echo "MATCH FOUND for FAQ (No Hamza) in Flow: " . $flow['name'] . "\n";
                }
                
                if (strtolower(trim($msg_prices)) == $msg_trigger) {
                    echo "MATCH FOUND for Prices in Flow: " . $flow['name'] . "\n";
                }
            }
        }
    }
}
echo "Done.\n";
?>
