import { AlTriggerStream, AlEntitlementCollection, AlSession, AlRuntimeConfiguration, ConfigOption } from '@al/core';
import { __awaiter, __generator } from 'tslib';

var AlNavigationServiceMock = /** @class */ (function () {
    function AlNavigationServiceMock() {
        this.queryParams = {};
        this.entitlements = true;
        this.events = new AlTriggerStream();
        this.isNavigationAllowed = true;
        this.navigate = {
            byNamedRoute: function (routeId, parameters) {
                // empty intentional
            },
            byRoute: function () {
                // empty intentional
            },
            byNgRoute: function () {
                // empty intentional
            }
        };
        this.router = {
            getCurrentNavigation: function () {
                return {
                    extras: {
                        state: {}
                    }
                };
            }
        };
    }
    AlNavigationServiceMock.prototype.setNavigationBlock = function () {
        this.isNavigationAllowed = false;
    };
    AlNavigationServiceMock.prototype.clearNavigationBlock = function () {
        this.isNavigationAllowed = true;
    };
    AlNavigationServiceMock.prototype.setActiveEntitlements = function () {
        var productIds = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            productIds[_i] = arguments[_i];
        }
        this.entitlements = new AlEntitlementCollection(productIds.map(function (productId) {
            return {
                productId: productId,
                active: true,
                expires: new Date(Date.now() + 86400000)
            };
        }));
    };
    AlNavigationServiceMock.prototype.evaluateEntitlementExpression = function (expression) {
        if (typeof (this.entitlements) === 'boolean') {
            return this.entitlements;
        }
        return this.entitlements.evaluateExpression(expression);
    };
    AlNavigationServiceMock.prototype.setRouteParameter = function (parameter, value) {
        // empty intentional
    };
    AlNavigationServiceMock.prototype.isExperienceAvailable = function (xpId) {
        return false;
    };
    AlNavigationServiceMock.prototype.getNavigationSchema = function (schemaId) {
        return Promise.resolve({});
    };
    AlNavigationServiceMock.prototype.resolveURL = function (url, parameters, context) {
        if (parameters === void 0) { parameters = {}; }
        return '';
    };
    AlNavigationServiceMock.prototype.track = function () { };
    AlNavigationServiceMock.prototype.trackUsageEvent = function () { };
    return AlNavigationServiceMock;
}());

function setAuthState(accountId, actingAccountId, userId) {
    if (accountId === void 0) { accountId = '2'; }
    if (actingAccountId === void 0) { actingAccountId = '2'; }
    if (userId === void 0) { userId = '1001-ABCDEF00-10105060-1234'; }
    return __awaiter(this, void 0, void 0, function () {
        var nowTS, sessionData;
        return __generator(this, function (_a) {
            if (accountId === null) {
                AlSession.deactivateSession();
                return [2 /*return*/];
            }
            nowTS = Date.now() / 1000;
            sessionData = {
                authentication: {
                    user: {
                        id: userId,
                        name: 'Mister McNielsen',
                        email: 'mcnielsen@alertlogic.com',
                        active: true,
                        locked: false,
                        version: 1002,
                        linked_users: [],
                        created: {
                            at: 123456789,
                            by: 'McNielsen',
                        },
                        modified: {
                            at: 123456790,
                            by: 'Warsaw',
                        }
                    },
                    account: {
                        id: accountId,
                        name: "Kevin's Fast Company",
                        active: true,
                        accessible_locations: [
                            "defender-us-denver",
                            "insight-us-virginia"
                        ],
                        default_location: 'defender-us-denver',
                        created: {
                            at: 123456789,
                            by: 'McNielsen',
                        },
                        modified: {
                            at: 123456790,
                            by: 'Warsaw',
                        }
                    },
                    token: 'BigFatFakeToken',
                    token_expiration: nowTS + 86400,
                }
            };
            if (actingAccountId !== accountId) {
                sessionData.acting = Object.assign({}, sessionData.authentication.account);
                sessionData.acting.id = actingAccountId;
                sessionData.acting.name = "Kevin's Slow Company";
            }
            AlRuntimeConfiguration.setOption(ConfigOption.ResolveAccountMetadata, false);
            return [2 /*return*/, AlSession.setAuthentication(sessionData)];
        });
    });
}
function timeoutPromise(delay) {
    return __awaiter(this, void 0, void 0, function () {
        return __generator(this, function (_a) {
            return [2 /*return*/, new Promise(function (resolve, reject) {
                    setTimeout(function () {
                        resolve();
                    }, delay);
                })];
        });
    });
}
function createEntitlementSet(entitlements) {
    if (entitlements === void 0) { entitlements = []; }
    return new AlEntitlementCollection(entitlements.map(function (entitlementId) {
        var date = new Date();
        date.setDate(date.getDate() + 1);
        return {
            productId: entitlementId,
            active: true,
            expires: date
        };
    }));
}

/*
 * Public API Surface of design-client
 */

/**
 * Generated bundle index. Do not edit.
 */

export { AlNavigationServiceMock, createEntitlementSet, setAuthState, timeoutPromise };
//# sourceMappingURL=al-ng-navigation-components-testing.js.map
