function defineStructure() {
    addColumn("status");   // Código HTTP ou "Erro"
    addColumn("mensagem"); // Retorno da API ou sucesso
    addColumn("erro");     // Mensagem de erro, se houver
}

function onSync(lastSyncDate) {}

function onMobileSync(user) {}

function createDataset(fields, constraints, sortFields) {
    var serviceCode = "API Protheus Full";
    var endpoint = "/uf_mata010";
    var method = "post";
    var params = "";

    if (constraints) {
        constraints.forEach(function(c) {
            if (c.fieldName == "serviceCode") serviceCode = c.initialValue;
            if (c.fieldName == "endpoint") endpoint = c.initialValue;
            if (c.fieldName == "method") method = c.initialValue.toLowerCase();
            if (c.fieldName == "params") params = c.initialValue;
        });
    }

    var dataset = DatasetBuilder.newDataset();

    try {
        var serviceHelper = ServiceManager.getService(serviceCode);
        var serviceLocator = serviceHelper.instantiate("com.totvs.technology.ajax.http.HttpClientService");

        var data = serviceLocator.invoke({
            "endpoint": endpoint,
            "method": method,
            "timeout": 5000,
            "mediaType": "application/json",
            "content": params
        });

        dataset.addRow(["200", data, ""]); // Sucesso

    } catch (e) {
        dataset.addRow(["Erro", "", e.message]); // Captura erro detalhado
    }

    return dataset;
}
