"use strict";
/***
 * alasqlFunctionImporter.js
 *
 * PUrpose of this is to set up a central module to define and import custom functions into alasql
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
const alasqlExtension = __importStar(require("../utility/functions/sql/alaSQLExtension.js"));
const dateFunctions = __importStar(require("../utility/functions/date/dateFunctions.js"));
const geo = __importStar(require("../utility/functions/geo.js"));
//import the custom function, need to define an upper and lower case version of the function so it is parsed properly in alasql
function default_1(alasql) {
    /*
    AGGREGATE FUNCTIONS
     */
    alasql.aggr.mad = alasql.aggr.MAD = alasqlExtension.mad;
    alasql.aggr.mean = alasql.aggr.MEAN = alasqlExtension.mean;
    alasql.aggr.mode = alasql.aggr.MODE = alasqlExtension.mode;
    alasql.aggr.prod = alasql.aggr.PROD = alasqlExtension.prod;
    //we are overriding alasql's median function as their algorithm is incorrect
    alasql.aggr.median = alasql.aggr.MEDIAN = alasqlExtension.median;
    /*
    CUSTOM FUNCTIONS
     */
    alasql.fn.distinct_array = alasql.fn.DISTINCT_ARRAY = alasqlExtension.distinct_array;
    alasql.fn.search_json = alasql.fn.SEARCH_JSON = alasqlExtension.searchJSON;
    alasql.fn.__ala__ = alasql;
    //Date Functions...
    alasql.fn.current_date = alasql.fn.CURRENT_DATE = dateFunctions.current_date;
    alasql.fn.current_time = alasql.fn.CURRENT_TIME = dateFunctions.current_time;
    alasql.fn.extract = alasql.fn.EXTRACT = dateFunctions.extract;
    alasql.fn.date = alasql.fn.DATE = dateFunctions.date;
    alasql.fn.date_format = alasql.fn.DATE_FORMAT = dateFunctions.date_format;
    alasql.fn.date_add = alasql.fn.DATE_ADD = dateFunctions.date_add;
    alasql.fn.date_sub = alasql.fn.DATE_SUB = dateFunctions.date_sub;
    alasql.fn.date_diff = alasql.fn.DATE_DIFF = alasql.fn.datediff = alasql.fn.DATEDIFF = dateFunctions.date_diff;
    alasql.fn.now = alasql.fn.NOW = dateFunctions.now;
    alasql.fn.offset_utc = alasql.fn.OFFSET_UTC = dateFunctions.offset_utc;
    alasql.fn.get_server_time = alasql.fn.GET_SERVER_TIME = dateFunctions.get_server_time;
    //GETDATE() and CURRENT_TIMESTAMP reference the date/time value from NOW() in alasql but we need to monkey patch
    // them here as well with the new now logic
    alasql.fn.getdate = alasql.fn.GETDATE = dateFunctions.now;
    alasql.fn.current_timestamp = alasql.fn.CURRENT_TIMESTAMP = dateFunctions.now;
    /*
    CUSTOM GEO FUNCTIONS
     */
    alasql.fn.geoarea = alasql.fn.GEOAREA = alasql.fn.geoArea = geo.geoArea;
    alasql.fn.geocircle = alasql.fn.GEOCIRCLE = alasql.fn.geoCircle = geo.geoCircle;
    alasql.fn.geocontains = alasql.fn.GEOCONTAINS = alasql.fn.geoContains = geo.geoContains;
    alasql.fn.geoconvert = alasql.fn.GEOCONVERT = alasql.fn.geoConvert = geo.geoConvert;
    alasql.fn.geocrosses = alasql.fn.GEOCROSSES = alasql.fn.geoCrosses = geo.geoCrosses;
    alasql.fn.geodifference = alasql.fn.GEODIFFERENCE = alasql.fn.geoDifference = geo.geoDifference;
    alasql.fn.geodistance = alasql.fn.GEODISTANCE = alasql.fn.geoDistance = geo.geoDistance;
    alasql.fn.geoequal = alasql.fn.GEOEQUAL = alasql.fn.geoEqual = geo.geoEqual;
    alasql.fn.geolength = alasql.fn.GEOLENGTH = alasql.fn.geoLength = geo.geoLength;
    alasql.fn.geonear = alasql.fn.GEONEAR = alasql.fn.geoNear = geo.geoNear;
}
//# sourceMappingURL=alasqlFunctionImporter.js.map