<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

require_once __DIR__ . '/../services/facto/FactoCustomersSyncService.php';

header('Content-Type: text/plain; charset=utf-8');

try {
    $perPage = isset($_GET['per_page']) ? (int) $_GET['per_page'] : 100;

    if ($perPage <= 0) {
        $perPage = 100;
    }

    $sync = new FactoCustomersSyncService();
    $count = $sync->syncCustomers($perPage);

    echo "OK SYNC CUSTOMERS" . PHP_EOL;
    echo "Clientes nuevos guardados: " . $count . PHP_EOL;

} catch (Exception $e) {
    echo "ERROR SYNC CUSTOMERS" . PHP_EOL;
    echo $e->getMessage() . PHP_EOL;
}