<?php
/**
 * Syncro RMM integration service (stub).
 *
 * This is a placeholder for the SyncroRMM lead creation and customer
 * lookup functionality. The full implementation will be added when
 * Syncro API credentials and endpoint details are finalized.
 */

// Deny direct access
if (basename($_SERVER['SCRIPT_FILENAME'] ?? '') === basename(__FILE__)) {
    http_response_code(403);
    exit('Direct access denied.');
}

require_once __DIR__ . '/../helpers.php';

/**
 * Sync a quote to SyncroRMM as a lead.
 *
 * Checks for an existing customer by email/business name, then creates
 * a lead in Syncro with the quote details.
 *
 * @param PDO   $db    Database connection.
 * @param array $quote Quote row from database.
 * @return array Result with keys: synced, is_existing_customer, syncro_lead_id, error
 */
function sync_quote_to_syncro(PDO $db, array $quote): array
{
    $result = [
        'synced'               => false,
        'is_existing_customer' => false,
        'syncro_lead_id'       => null,
        'error'                => 'Syncro integration not yet configured',
    ];

    if (empty($quote['contact_email'])) {
        $result['error'] = 'Quote has no contact email';
        return $result;
    }

    app_log('INFO', "Syncro sync requested for quote {$quote['id']} - integration not yet configured");

    return $result;
}
