"use strict";
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 (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (g && (g = 0, op[0] && (_ = 0)), _) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.newConfigurationProvider = exports.getFullConfiguration = exports.setEnvironment = exports.getEnvironment = exports.getGlobals = exports.setGlobals = exports.setConfigurationProvider = exports.getConfigurationProvider = exports.resendConfirmationEmail = exports.sendOtpEmail = exports.loginWithOtp = exports.login = exports.loginInternal = exports.initWithOneTimeCode = exports.initWithAuthToken = exports.initWithEmail = exports.initWithSessionCode = exports.setConfigurations = exports.BringgDashboardSDK = void 0;
var mobx = __importStar(require("mobx"));
var AddonsApi_1 = __importDefault(require("./Addons/AddonsApi"));
var AlertsApi_1 = __importDefault(require("./Alerts/AlertsApi"));
var AnalyticsReportsApi_1 = __importDefault(require("./AnalyticsReports/AnalyticsReportsApi"));
var ApplicationApi_1 = __importDefault(require("./Application/ApplicationApi"));
var ApplicationMerchantConfigurationApi_1 = __importDefault(require("./ApplicationMerchantConfiguration/ApplicationMerchantConfigurationApi"));
var ApplicationTeamConfigurationApi_1 = __importDefault(require("./ApplicationTeamConfiguration/ApplicationTeamConfigurationApi"));
var AsyncOperationStatus_1 = require("./AsyncOperationStatus");
var BillingApi_1 = __importDefault(require("./Billing/BillingApi"));
var CapacityInsightsApi_1 = __importDefault(require("./CapacityPlanningInsights/CapacityInsightsApi"));
var Chat_1 = __importDefault(require("./Chat/Chat"));
var ChatConversationApi_1 = __importDefault(require("./ChatConversation/ChatConversationApi"));
var Company_1 = __importDefault(require("./Company/Company"));
var ConfigurationProvider_1 = require("./Core/ConfigurationProvider");
var Crew_1 = __importDefault(require("./Crew/Crew"));
var CrossAppTransport_1 = __importDefault(require("./CrossAppTranport/CrossAppTransport"));
var CustomAttributesApi_1 = __importDefault(require("./CustomAttributes/CustomAttributesApi"));
var customers_api_1 = __importDefault(require("./Customer/v2/customers-api"));
var CustomerAvailabilityHourApi_1 = __importDefault(require("./CustomerAvailabilityHour/CustomerAvailabilityHourApi"));
var customer_configuration_1 = __importDefault(require("./CustomerConfiguration/customer.configuration"));
var DeliveryBlocksApi_1 = require("./DeliveryBlocks/DeliveryBlocksApi");
var DeliveryCatalogApi_1 = __importDefault(require("./DeliveryCatalog/DeliveryCatalogApi"));
var DeliveryCatalogApi_2 = __importDefault(require("./DeliveryCatalogGeneralEnv/DeliveryCatalogApi"));
var delivery_windows_api_1 = __importDefault(require("./DeliveryWindows/v2/delivery-windows-api"));
var ExclusionWindowApi_1 = __importDefault(require("./ExclusionWindow/ExclusionWindowApi"));
var exclusion_window_api_1 = require("./ExclusionWindow/v2/exclusion-window-api");
var FleetApi_1 = __importDefault(require("./Fleet/FleetApi"));
var FleetRouterApi_1 = __importDefault(require("./FleetRouter/FleetRouterApi"));
var FleetTemplateApi_1 = __importDefault(require("./FleetTemplate/FleetTemplateApi"));
var FloatingInventoryApi_1 = __importDefault(require("./FloatingInventory/FloatingInventoryApi"));
var floating_inventories_api_1 = require("./FloatingInventory/v2/floating-inventories-api");
var GeocodingApi_1 = __importDefault(require("./Geocoding/GeocodingApi"));
var GoogleMapsHelperApi_1 = __importDefault(require("./GoogleMapsHelper/GoogleMapsHelperApi"));
var Inventory_1 = __importDefault(require("./Inventory/Inventory"));
var InventoryActionsConfiguration_1 = __importDefault(require("./InventoryActionsConfiguration/InventoryActionsConfiguration"));
var Language_1 = require("./Language/Language");
var lookup_api_1 = __importDefault(require("./LookUp/lookup-api"));
var MerchantApi_1 = __importDefault(require("./Merchant/MerchantApi"));
var MerchantConfigurationApi_1 = require("./MerchantConfiguration/MerchantConfigurationApi");
var MerchantPrototypeApi_1 = __importDefault(require("./MerchantPrototype/MerchantPrototypeApi"));
var NotificationTemplate_1 = require("./NotificationTemplate/NotificationTemplate");
var NotificationType_1 = require("./NotificationType/NotificationType");
var OauthApplicationApi_1 = __importDefault(require("./OauthApplications/OauthApplicationApi"));
var OnboardingApi_1 = __importDefault(require("./Onboarding/OnboardingApi"));
var OpenFleetApi_1 = __importDefault(require("./OpenFleet/OpenFleetApi"));
var OptimizationConfiguration_1 = __importDefault(require("./OptimizationConfiguration/OptimizationConfiguration"));
var OptimizationConfigurationV2_1 = __importDefault(require("./OptimizationConfigurationV2/OptimizationConfigurationV2"));
var OptimizationKpiApi_1 = __importDefault(require("./OptimizationKpi/v2/OptimizationKpiApi"));
var optimization_result_api_1 = __importDefault(require("./OptimizationResult/optimization-result-api"));
var order_execution_actions_api_1 = __importDefault(require("./OrderExecutionActions/order-execution-actions-api"));
var PackageApi_1 = __importDefault(require("./Package/PackageApi"));
var ParkingSpotApi_1 = __importDefault(require("./ParkingSpot/ParkingSpotApi"));
var parking_spot_api_1 = __importDefault(require("./ParkingSpot/v2/parking-spot-api"));
var Photo_1 = __importDefault(require("./Photo/Photo"));
var planned_delivery_windows_api_1 = __importDefault(require("./PlannedDeliveryWindows/planned-delivery-windows-api"));
var PlannedRoutesApi_1 = __importDefault(require("./PlannedRoutes/PlannedRoutesApi"));
var preset_views_api_1 = __importDefault(require("./PresetViews/preset-views-api"));
var PrivilegesApi_1 = __importDefault(require("./Privileges/PrivilegesApi"));
var PushNotificationRegistration_1 = __importDefault(require("./PushNotificationRegistration/PushNotificationRegistration"));
var PushTokenSubscriptionApi_1 = __importDefault(require("./PushTokenSubscription/PushTokenSubscriptionApi"));
var RatesApi_1 = __importDefault(require("./Rates/RatesApi"));
var ReasonToCancelTasksApi_1 = __importDefault(require("./ReasonToCancelTasks/ReasonToCancelTasksApi"));
var ReasonToChangeInventory_1 = __importDefault(require("./ReasonToChangeInventory/ReasonToChangeInventory"));
var ReasonToReassignTasksApi_1 = __importDefault(require("./ReasonToReassignTask/ReasonToReassignTasksApi"));
var RelayApi_1 = __importDefault(require("./Relay/RelayApi"));
var ReportPreference_1 = __importDefault(require("./ReportPreference/ReportPreference"));
var reports_1 = __importDefault(require("./Reports/reports"));
var ResourceUploadApi_1 = __importDefault(require("./ResourceUpload/ResourceUploadApi"));
var ResourceUtilizationApi_1 = __importDefault(require("./ResourceUtilization/ResourceUtilizationApi"));
var RolloutsApi_1 = __importDefault(require("./Rollouts/RolloutsApi"));
var RouteOptimizationApi_1 = __importDefault(require("./RouteOptimization/RouteOptimizationApi"));
var RouteOptimizationService_1 = __importDefault(require("./RouteOptimization/RouteOptimizationService"));
var RuleApi_1 = __importDefault(require("./Rule/RuleApi"));
var runs_api_1 = __importDefault(require("./Run/v2/runs-api"));
var ScanApi_1 = __importDefault(require("./Scan/ScanApi"));
var SecurityConfigurationApi_1 = __importDefault(require("./SecurityConfiguration/SecurityConfigurationApi"));
var ServiceApi_1 = __importDefault(require("./Service/ServiceApi"));
var ServiceAreaApi_1 = __importDefault(require("./ServiceArea/ServiceAreaApi"));
var service_area_api_1 = require("./ServiceArea/v2/service-area-api");
var ServicePlansApi_1 = __importDefault(require("./ServicePlans/ServicePlansApi"));
var AuthService_1 = __importDefault(require("./Services/Identity/AuthService"));
var Session_1 = __importDefault(require("./Services/Identity/Session"));
var ShiftsApi_1 = __importDefault(require("./Shifts/ShiftsApi"));
var Signature_1 = __importDefault(require("./Signature/Signature"));
var SkillsApi_1 = __importDefault(require("./Skills/SkillsApi"));
var SpeedFactor_1 = __importDefault(require("./SpeedFactor/SpeedFactor"));
var SupportTicketApi_1 = __importDefault(require("./SupportTicket/SupportTicketApi"));
var Tag_1 = __importDefault(require("./Tag/Tag"));
var tags_api_1 = __importDefault(require("./Tag/v2/tags-api"));
var TagCustomerConfiguration_1 = __importDefault(require("./TagCustomerConfiguration/TagCustomerConfiguration"));
var TagMerchantConfiguration_1 = __importDefault(require("./TagMerchantConfiguration/TagMerchantConfiguration"));
var TaskApi_1 = __importDefault(require("./Task/TaskApi"));
var tasks_api_1 = __importDefault(require("./Task/v2/tasks-api"));
var TaskConfiguration_1 = __importDefault(require("./TaskConfiguration/TaskConfiguration"));
var TaskInventory_1 = __importDefault(require("./TaskInventory/TaskInventory"));
var TaskManagedAttributes_1 = require("./TaskManagedAttributes");
var task_reject_reasons_api_1 = __importDefault(require("./TaskRejectReason/v2/task-reject-reasons-api"));
var tasks_explorer_api_1 = __importDefault(require("./TasksExplorer/v2/tasks-explorer-api"));
var TeamApi_1 = __importDefault(require("./Team/TeamApi"));
var TeamConfigurationApi_1 = __importDefault(require("./TeamConfiguration/TeamConfigurationApi"));
var TeamServiceAreaApi_1 = __importDefault(require("./TeamServiceArea/TeamServiceAreaApi"));
var TemplatesApi_1 = __importDefault(require("./Templates/TemplatesApi"));
var upload_api_1 = __importDefault(require("./Upload/v2/upload-api"));
var Users_1 = __importDefault(require("./User/Users"));
var users_api_1 = __importDefault(require("./User/v2/users-api"));
var UserAnalyticsApi_1 = __importDefault(require("./UserAnalytics/UserAnalyticsApi"));
var UserConfiguration_1 = __importDefault(require("./UserConfiguration/UserConfiguration"));
var user_preset_views_api_1 = __importDefault(require("./UserPresetViews/user-preset-views-api"));
var UserTypeApi_1 = __importDefault(require("./UserType/UserTypeApi"));
var vehicles_api_1 = __importDefault(require("./Vehicle/v2/vehicles-api"));
var VehicleApi_1 = __importDefault(require("./Vehicle/VehicleApi"));
var VehicleCategoryApi_1 = __importDefault(require("./VehicleCategory/VehicleCategoryApi"));
var vehicle_types_api_1 = __importDefault(require("./VehicleType/v2/vehicle-types-api"));
var VehicleTypeApi_1 = __importDefault(require("./VehicleType/VehicleTypeApi"));
var VrpAutoDispatchAnalyticApi_1 = __importDefault(require("./VrpAutoDispatchAnalytic/VrpAutoDispatchAnalyticApi"));
var WebApplicationConfigurationApi_1 = __importDefault(require("./WebApplicationConfiguration/WebApplicationConfigurationApi"));
var WebhookAuthenticationConfiguration_1 = __importDefault(require("./WebhookAuthenticationConfiguration/WebhookAuthenticationConfiguration"));
var workflows_api_1 = __importDefault(require("./Workflow/v2/workflows-api"));
var environment = 'production';
var configurationProvider = null;
var globals = null;
var BringgDashboardSDK = /** @class */ (function () {
    function BringgDashboardSDK(session) {
        this.applicationMerchantConfiguration = null;
        this.applicationTeamConfiguration = null;
        this.chat = null;
        this.optimizationKpi = null;
        this.companies = null;
        this.credentials = {};
        this.crews = null;
        this.crossAppTransport = null;
        this.customerConfiguration = null;
        this.deliveryBlocks = null;
        this.fleets = null;
        this.rules = null;
        this.floatingInventory = null;
        this.inventoryActionsConfigurations = null;
        this.languages = null;
        this.merchant = null;
        this.merchantConfiguration = null;
        this.merchantPrototype = null;
        this.notificationTemplates = null;
        this.notificationTypes = null;
        this.oauthApplication = null;
        this.plannedRoutes = null;
        this.privileges = null;
        this.reasonToChangeInventory = null;
        this.reasonToReassignTasks = null;
        this.reasonToCancelTasks = null;
        this.reportPreferences = null;
        this.reports = null;
        this.rollouts = null;
        this.securityConfiguration = null;
        this.skills = null;
        this.speedFactor = null;
        this.taskConfigurations = null;
        this.taskInventory = null;
        this.inventory = null;
        this.tasks = null;
        this.teamConfiguration = null;
        this.teams = null;
        this.resourceUploads = null;
        this.userConfigurations = null;
        this.users = null;
        this.vehicleCategories = null;
        this.vehicleTypes = null;
        this.vehicles = null;
        this.session = session;
        this.session.sdk = this;
    }
    BringgDashboardSDK.setConfigurations = function (apiEndpointURL, monitorEndpointURL, generalEnvApiEndpoint) {
        configurationProvider.getApiEndpoint = function () { return apiEndpointURL; };
        configurationProvider.getAuthenticationEndpoint = function () { return apiEndpointURL; };
        configurationProvider.getRegionDiscoveryEndpoint = function () { return apiEndpointURL; };
        configurationProvider.getMonitoringEndpoint = function () { return monitorEndpointURL; };
        configurationProvider.getGeneralEnvApiEndpoint = function () { return generalEnvApiEndpoint; };
    };
    BringgDashboardSDK.initWithSessionCode = function (code, session, region, globals) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, BringgDashboardSDK.login({ code: code, session: session, region: region, globals: globals })];
                    case 1: return [2 /*return*/, _a.sent()];
                }
            });
        });
    };
    BringgDashboardSDK.initWithEmail = function (email, password, merchant_uuid, recaptchaToken, recaptcha_qa_token, region, globals) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, BringgDashboardSDK.login({
                            email: email,
                            password: password,
                            merchant_uuid: merchant_uuid,
                            recaptchaToken: recaptchaToken,
                            recaptcha_qa_token: recaptcha_qa_token,
                            region: region,
                            globals: globals
                        })];
                    case 1: return [2 /*return*/, _a.sent()];
                }
            });
        });
    };
    BringgDashboardSDK.initWithAuthToken = function (region, authenticationToken, globals) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, BringgDashboardSDK.login({ region: region, authenticationToken: authenticationToken, globals: globals })];
                    case 1: return [2 /*return*/, _a.sent()];
                }
            });
        });
    };
    BringgDashboardSDK.initWithOneTimeCode = function (region, token, secret, globals) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, BringgDashboardSDK.login({ region: region, token: token, secret: secret, globals: globals })];
                    case 1: return [2 /*return*/, _a.sent()];
                }
            });
        });
    };
    BringgDashboardSDK.loginInternal = function (sdkInitializer, params) {
        return __awaiter(this, void 0, void 0, function () {
            var response;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, Session_1.default.init(params)];
                    case 1:
                        response = _a.sent();
                        return [2 /*return*/, sdkInitializer(response)];
                }
            });
        });
    };
    BringgDashboardSDK.login = function (params) {
        var _a;
        return __awaiter(this, void 0, void 0, function () {
            var env, configuration;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        setGlobals(params.globals);
                        env = getEnvironment();
                        if (!(['production', 'staging', 'edge'].includes(env) && !((_a = getConfigurationProvider()) === null || _a === void 0 ? void 0 : _a.isLoadedFromEndpoint))) return [3 /*break*/, 2];
                        return [4 /*yield*/, ConfigurationProvider_1.ConfigurationProvider.fromUrl({
                                urlReceived: ConfigurationProvider_1.ConfigurationProvider.getConfigUrl(env),
                                fallbackConfig: getFullConfiguration(),
                                commonRegionConfigKeys: getConfigurationProvider().getCommonRegionConfigKeys(),
                                specificRegionConfigkeys: getConfigurationProvider().getRegionSpecificConfigKeys(),
                                clientId: getConfigurationProvider().getClientId()
                            })];
                    case 1:
                        configuration = _b.sent();
                        if (configuration) {
                            BringgDashboardSDK.setConfigurationProvider(configuration);
                        }
                        _b.label = 2;
                    case 2: return [4 /*yield*/, this.loginInternal(function (a) { return init(a); }, params)];
                    case 3: return [2 /*return*/, _b.sent()];
                }
            });
        });
    };
    BringgDashboardSDK.loginWithOtp = function (email, password, otp, merchant_uuid, region, recaptchaToken, recaptcha_qa_token) {
        return __awaiter(this, void 0, void 0, function () {
            var response;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, Session_1.default.init({
                            email: email,
                            password: password,
                            otp: otp,
                            merchant_uuid: merchant_uuid,
                            region: region,
                            recaptchaToken: recaptchaToken,
                            recaptcha_qa_token: recaptcha_qa_token
                        })];
                    case 1:
                        response = _a.sent();
                        return [2 /*return*/, init(response)];
                }
            });
        });
    };
    BringgDashboardSDK.prototype.logout = function (keepServerSession) {
        if (keepServerSession === void 0) { keepServerSession = false; }
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.session.logout(keepServerSession)];
                    case 1: return [2 /*return*/, _a.sent()];
                }
            });
        });
    };
    BringgDashboardSDK.resendConfirmationEmail = function (params) {
        return __awaiter(this, void 0, void 0, function () {
            var authService, email, password, merchant_uuid, recaptchaToken, recaptcha_qa_token;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        authService = AuthService_1.default.init(params.region);
                        email = params.email, password = params.password, merchant_uuid = params.merchant_uuid, recaptchaToken = params.recaptchaToken, recaptcha_qa_token = params.recaptcha_qa_token;
                        return [4 /*yield*/, authService.resendConfirmationEmail(email, password, merchant_uuid, recaptchaToken, recaptcha_qa_token)];
                    case 1: return [2 /*return*/, _a.sent()];
                }
            });
        });
    };
    BringgDashboardSDK.prototype.switchAccounts = function () {
        return __awaiter(this, void 0, void 0, function () {
            var _a;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        _a = init;
                        return [4 /*yield*/, this.session.switchAccounts()];
                    case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
                }
            });
        });
    };
    BringgDashboardSDK.prototype.impersonate = function (user_id) {
        return __awaiter(this, void 0, void 0, function () {
            var _a;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        _a = init;
                        return [4 /*yield*/, this.session.impersonate(user_id)];
                    case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
                }
            });
        });
    };
    BringgDashboardSDK.prototype.impersonateByTeam = function (team_id) {
        return __awaiter(this, void 0, void 0, function () {
            var _a;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        _a = init;
                        return [4 /*yield*/, this.session.impersonateByTeam(team_id)];
                    case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
                }
            });
        });
    };
    BringgDashboardSDK.prototype.unwindImpersonation = function () {
        return __awaiter(this, void 0, void 0, function () {
            var _a;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        _a = init;
                        return [4 /*yield*/, this.session.unwindImpersonation()];
                    case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
                }
            });
        });
    };
    BringgDashboardSDK.sendOtpEmail = function (params) {
        return __awaiter(this, void 0, void 0, function () {
            var authService, email, protected_action;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        authService = AuthService_1.default.init(params.region);
                        email = params.email, protected_action = params.protected_action;
                        return [4 /*yield*/, authService.sendOtpEmail(email, protected_action)];
                    case 1: return [2 /*return*/, _a.sent()];
                }
            });
        });
    };
    BringgDashboardSDK.setConfigurationProvider = setConfigurationProvider;
    BringgDashboardSDK.setEnvironment = setEnvironment;
    BringgDashboardSDK.getFullConfiguration = getFullConfiguration;
    BringgDashboardSDK.newConfigurationProvider = newConfigurationProvider;
    return BringgDashboardSDK;
}());
exports.BringgDashboardSDK = BringgDashboardSDK;
function init(session) {
    return __awaiter(this, void 0, void 0, function () {
        var bringg, workflows, taskRejectReasons;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    bringg = new BringgDashboardSDK(session);
                    bringg.v2 = {
                        vehicles: new vehicles_api_1.default(session),
                        relay: new RelayApi_1.default(session),
                        tasks: new tasks_api_1.default(session),
                        users: new users_api_1.default(session),
                        tags: new tags_api_1.default(session),
                        customers: new customers_api_1.default(session),
                        plannedDeliveryWindows: new planned_delivery_windows_api_1.default(session),
                        optimizationResultApi: new optimization_result_api_1.default(session),
                        exclusionWindow: new exclusion_window_api_1.ExclusionWindowApi(session),
                        serviceAreas: new service_area_api_1.ServiceAreaApi(session),
                        lookup: new lookup_api_1.default(session),
                        createWorkflows: function (mapper) {
                            workflows = new workflows_api_1.default(session, mapper);
                            return workflows;
                        },
                        workflows: function () {
                            return workflows;
                        },
                        createTaskRejectReasons: function (mapper) {
                            taskRejectReasons = new task_reject_reasons_api_1.default(session, mapper);
                            return taskRejectReasons;
                        },
                        taskRejectReasons: function () {
                            return taskRejectReasons;
                        },
                        runs: new runs_api_1.default(session, function () { return bringg; }),
                        uploads: new upload_api_1.default(session),
                        floatingInventories: new floating_inventories_api_1.FloatingInventoriesApi(session),
                        deliveryWindows: new delivery_windows_api_1.default(session),
                        taskManagedAttributes: new TaskManagedAttributes_1.TaskManagedAttributesApi(session),
                        chat: new Chat_1.default(session),
                        optimizationKpi: new OptimizationKpiApi_1.default(session),
                        tasksExplorer: new tasks_explorer_api_1.default(session),
                        vehiclesTypesApi: new vehicle_types_api_1.default(session),
                        parkingSpotApi: new parking_spot_api_1.default(session)
                    };
                    bringg.application = new ApplicationApi_1.default(session);
                    bringg.chat = new ChatConversationApi_1.default(session);
                    bringg.companies = new Company_1.default(session);
                    bringg.crossAppTransport = new CrossAppTransport_1.default();
                    bringg.customerConfiguration = new customer_configuration_1.default(session);
                    bringg.deliveryBlocks = new DeliveryBlocksApi_1.DeliveryBlocksApi(session);
                    bringg.fleets = new FleetApi_1.default(session);
                    bringg.rules = new RuleApi_1.default(session);
                    bringg.fleetRouterApi = new FleetRouterApi_1.default(session);
                    bringg.floatingInventory = new FloatingInventoryApi_1.default(session);
                    bringg.geocoding = new GeocodingApi_1.default(session);
                    bringg.googleMapsHelper = new GoogleMapsHelperApi_1.default(session);
                    bringg.inventoryActionsConfigurations = new InventoryActionsConfiguration_1.default(session);
                    bringg.languages = new Language_1.Language(session);
                    bringg.merchant = new MerchantApi_1.default(session);
                    bringg.merchantConfiguration = new MerchantConfigurationApi_1.MerchantConfigurationApi(session);
                    bringg.merchantPrototype = new MerchantPrototypeApi_1.default(session);
                    bringg.notificationTemplates = new NotificationTemplate_1.NotificationTemplate(session);
                    bringg.notificationTypes = new NotificationType_1.NotificationType(session);
                    bringg.oauthApplication = new OauthApplicationApi_1.default(session);
                    bringg.onboardings = new OnboardingApi_1.default(session);
                    bringg.photos = new Photo_1.default(session);
                    bringg.plannedRoutes = new PlannedRoutesApi_1.default(session);
                    bringg.privileges = new PrivilegesApi_1.default(session);
                    bringg.pushTokenSubscription = new PushTokenSubscriptionApi_1.default(session);
                    bringg.pushNotificationRegistration = new PushNotificationRegistration_1.default(session);
                    bringg.reasonToChangeInventory = new ReasonToChangeInventory_1.default(session);
                    bringg.reasonToReassignTasks = new ReasonToReassignTasksApi_1.default(session);
                    bringg.reasonToCancelTasks = new ReasonToCancelTasksApi_1.default(session);
                    bringg.reportPreferences = new ReportPreference_1.default(session);
                    bringg.reports = new reports_1.default(session);
                    bringg.scans = new ScanApi_1.default(session);
                    bringg.rollouts = new RolloutsApi_1.default(session);
                    bringg.securityConfiguration = new SecurityConfigurationApi_1.default(session);
                    bringg.service = new ServiceApi_1.default(session);
                    bringg.signatures = new Signature_1.default(session);
                    bringg.skills = new SkillsApi_1.default(session);
                    bringg.speedFactor = new SpeedFactor_1.default(session);
                    bringg.tagCustomerConfigurations = new TagCustomerConfiguration_1.default(session);
                    bringg.tagMerchantConfigurations = new TagMerchantConfiguration_1.default(session);
                    bringg.tags = new Tag_1.default(session);
                    bringg.taskConfigurations = new TaskConfiguration_1.default(session);
                    bringg.taskInventory = new TaskInventory_1.default(session);
                    bringg.inventory = new Inventory_1.default(session);
                    bringg.tasks = new TaskApi_1.default(session);
                    bringg.teamConfiguration = new TeamConfigurationApi_1.default(session);
                    bringg.teams = new TeamApi_1.default(session);
                    bringg.resourceUploads = new ResourceUploadApi_1.default(session);
                    bringg.userConfigurations = new UserConfiguration_1.default(session);
                    bringg.userTypes = new UserTypeApi_1.default(session);
                    bringg.users = new Users_1.default(session);
                    bringg.vehicleCategories = new VehicleCategoryApi_1.default(session);
                    bringg.vehicleTypes = new VehicleTypeApi_1.default(session);
                    bringg.vehicles = new VehicleApi_1.default(session);
                    bringg.vrpAutoDispatchAnalytic = new VrpAutoDispatchAnalyticApi_1.default(session);
                    bringg.webApplicationConfiguration = new WebApplicationConfigurationApi_1.default(session);
                    bringg.webhookAuthenticationConfiguration = new WebhookAuthenticationConfiguration_1.default(session);
                    bringg.optimizationConfiguration = new OptimizationConfiguration_1.default(session);
                    bringg.optimizationConfigurationV2 = new OptimizationConfigurationV2_1.default(session);
                    bringg.fleetTemplates = new FleetTemplateApi_1.default(session);
                    bringg.openFleets = new OpenFleetApi_1.default(session);
                    bringg.customerAvailabilityHours = new CustomerAvailabilityHourApi_1.default(session);
                    bringg.exclusionWindows = new ExclusionWindowApi_1.default(session);
                    bringg.shifts = new ShiftsApi_1.default(session);
                    bringg.serviceAreas = new ServiceAreaApi_1.default(session);
                    bringg.teamServiceAreas = new TeamServiceAreaApi_1.default(session);
                    bringg.billing = new BillingApi_1.default(session);
                    bringg.userAnalytics = new UserAnalyticsApi_1.default(session);
                    bringg.analyticsReports = new AnalyticsReportsApi_1.default(session);
                    bringg.servicePlans = new ServicePlansApi_1.default(session);
                    bringg.alertsApi = new AlertsApi_1.default(session);
                    bringg.deliveryCatalog = new DeliveryCatalogApi_1.default(session);
                    bringg.deliveryCatalogGeneralEnv = new DeliveryCatalogApi_2.default(session);
                    bringg.packageApi = new PackageApi_1.default(session);
                    bringg.templatesApi = new TemplatesApi_1.default(session);
                    bringg.routeOptimizationApi = new RouteOptimizationApi_1.default(session);
                    bringg.ratesApi = new RatesApi_1.default(session);
                    bringg.routeOptimizationService = new RouteOptimizationService_1.default(session);
                    bringg.parkingSpotApi = new ParkingSpotApi_1.default(session);
                    bringg.customAttributesApi = new CustomAttributesApi_1.default(session);
                    bringg.asyncOperationStatus = new AsyncOperationStatus_1.AsyncOperationStatus(session);
                    bringg.addons = new AddonsApi_1.default(session);
                    bringg.supportTicket = new SupportTicketApi_1.default(session);
                    bringg.optimizationKpi = new OptimizationKpiApi_1.default(session);
                    bringg.orderExecutionActions = new order_execution_actions_api_1.default(session);
                    bringg.presetViews = new preset_views_api_1.default(session);
                    bringg.userPresetViews = new user_preset_views_api_1.default(session);
                    bringg.capacityInsights = new CapacityInsightsApi_1.default(session);
                    bringg.resourceUtilization = new ResourceUtilizationApi_1.default(session);
                    // dependent
                    bringg.crews = new Crew_1.default(session, bringg.users);
                    bringg.applicationMerchantConfiguration = new ApplicationMerchantConfigurationApi_1.default(session, bringg.merchantConfiguration);
                    bringg.applicationTeamConfiguration = new ApplicationTeamConfigurationApi_1.default(session);
                    return [4 /*yield*/, initSessionConfiguration(bringg)];
                case 1:
                    _a.sent();
                    return [2 /*return*/, Object.freeze(bringg)];
            }
        });
    });
}
function initSessionConfiguration(bringg) {
    var _a;
    return __awaiter(this, void 0, void 0, function () {
        var apiKey;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0: return [4 /*yield*/, Promise.all([bringg.merchantConfiguration.get(), bringg.webApplicationConfiguration.get()])];
                case 1:
                    _b.sent();
                    if (!((_a = configurationProvider === null || configurationProvider === void 0 ? void 0 : configurationProvider.isUserAnalyticsEnabled) === null || _a === void 0 ? void 0 : _a.call(configurationProvider))) return [3 /*break*/, 5];
                    apiKey = configurationProvider.getUserAnalyticsApiKey();
                    return [4 /*yield*/, bringg.userAnalytics.addSnippet({ apiKey: apiKey })];
                case 2:
                    _b.sent();
                    return [4 /*yield*/, bringg.merchant.get()];
                case 3:
                    _b.sent();
                    return [4 /*yield*/, bringg.userAnalytics.run({
                            apiKey: apiKey,
                            environment: environment
                        })];
                case 4:
                    _b.sent();
                    _b.label = 5;
                case 5: return [2 /*return*/];
            }
        });
    });
}
function setConfigurations() {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i] = arguments[_i];
    }
    return BringgDashboardSDK.setConfigurations.apply(BringgDashboardSDK, __spreadArray([], __read(args), false));
}
exports.setConfigurations = setConfigurations;
function initWithSessionCode() {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i] = arguments[_i];
    }
    return BringgDashboardSDK.initWithSessionCode.apply(BringgDashboardSDK, __spreadArray([], __read(args), false));
}
exports.initWithSessionCode = initWithSessionCode;
function initWithEmail() {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i] = arguments[_i];
    }
    return BringgDashboardSDK.initWithEmail.apply(BringgDashboardSDK, __spreadArray([], __read(args), false));
}
exports.initWithEmail = initWithEmail;
function initWithAuthToken() {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i] = arguments[_i];
    }
    return BringgDashboardSDK.initWithAuthToken.apply(BringgDashboardSDK, __spreadArray([], __read(args), false));
}
exports.initWithAuthToken = initWithAuthToken;
function initWithOneTimeCode() {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i] = arguments[_i];
    }
    return BringgDashboardSDK.initWithOneTimeCode.apply(BringgDashboardSDK, __spreadArray([], __read(args), false));
}
exports.initWithOneTimeCode = initWithOneTimeCode;
function loginInternal() {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i] = arguments[_i];
    }
    return BringgDashboardSDK.loginInternal.apply(BringgDashboardSDK, __spreadArray([], __read(args), false));
}
exports.loginInternal = loginInternal;
function login() {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i] = arguments[_i];
    }
    return BringgDashboardSDK.login.apply(BringgDashboardSDK, __spreadArray([], __read(args), false));
}
exports.login = login;
function loginWithOtp() {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i] = arguments[_i];
    }
    return BringgDashboardSDK.loginWithOtp.apply(BringgDashboardSDK, __spreadArray([], __read(args), false));
}
exports.loginWithOtp = loginWithOtp;
function sendOtpEmail() {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i] = arguments[_i];
    }
    return BringgDashboardSDK.sendOtpEmail.apply(BringgDashboardSDK, __spreadArray([], __read(args), false));
}
exports.sendOtpEmail = sendOtpEmail;
function resendConfirmationEmail() {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i] = arguments[_i];
    }
    return BringgDashboardSDK.resendConfirmationEmail.apply(BringgDashboardSDK, __spreadArray([], __read(args), false));
}
exports.resendConfirmationEmail = resendConfirmationEmail;
function getConfigurationProvider() {
    return configurationProvider;
}
exports.getConfigurationProvider = getConfigurationProvider;
function setConfigurationProvider(provider) {
    configurationProvider = provider;
}
exports.setConfigurationProvider = setConfigurationProvider;
function setGlobals(bringgGlobals) {
    var withDefaults = bringgGlobals || { mobx: mobx };
    withDefaults.mobx = withDefaults.mobx || mobx;
    globals = withDefaults;
}
exports.setGlobals = setGlobals;
function getGlobals() {
    return globals;
}
exports.getGlobals = getGlobals;
function getEnvironment() {
    return environment;
}
exports.getEnvironment = getEnvironment;
function setEnvironment(env) {
    environment = env;
}
exports.setEnvironment = setEnvironment;
function getFullConfiguration() {
    return getConfigurationProvider().getFullConfig();
}
exports.getFullConfiguration = getFullConfiguration;
function newConfigurationProvider(_a) {
    var config = _a.config, fallbackConfig = _a.fallbackConfig, clientId = _a.clientId, commonRegionConfigKeys = _a.commonRegionConfigKeys, specificRegionConfigkeys = _a.specificRegionConfigkeys, isLoadedFromEndpoint = _a.isLoadedFromEndpoint;
    return new ConfigurationProvider_1.ConfigurationProvider({
        config: config,
        fallbackConfig: fallbackConfig,
        clientId: clientId,
        commonRegionConfigKeys: commonRegionConfigKeys,
        specificRegionConfigkeys: specificRegionConfigkeys,
        isLoadedFromEndpoint: isLoadedFromEndpoint
    });
}
exports.newConfigurationProvider = newConfigurationProvider;
//# sourceMappingURL=BringgDashboardSDK.js.map