"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class ApplePortalCookieService {
    constructor() {
        this.userSessionCookies = {};
        this.validUserSessionCookieNames = ["myacinfo", "dqsid", "itctx", "itcdq", "acn01"];
        this.validWebSessionCookieNames = ["wosid", "woinst", "itctx"];
    }
    getWebSessionCookie(cookiesData) {
        const webSessionCookies = _.cloneDeep(this.userSessionCookies);
        const parsedCookies = this.parseCookiesData(cookiesData, this.validWebSessionCookieNames);
        _.each(parsedCookies, parsedCookie => webSessionCookies[parsedCookie.key] = parsedCookie.cookie);
        return _.values(webSessionCookies).join("; ");
    }
    getUserSessionCookie() {
        return _.values(this.userSessionCookies).join("; ");
    }
    updateUserSessionCookie(cookiesData) {
        const parsedCookies = this.parseCookiesData(cookiesData, this.validUserSessionCookieNames);
        _.each(parsedCookies, parsedCookie => this.userSessionCookies[parsedCookie.key] = parsedCookie.cookie);
    }
    parseCookiesData(cookiesData, validCookieNames) {
        const result = {};
        for (const c of cookiesData) {
            const parts = c.split(";");
            for (const cookie of parts) {
                const trimmedCookie = cookie.trim();
                const [cookieKey, cookieValue] = trimmedCookie.split("=");
                if (_.includes(validCookieNames, cookieKey)) {
                    result[cookieKey] = { key: cookieKey, value: cookieValue, cookie: trimmedCookie };
                }
            }
        }
        return result;
    }
}
exports.ApplePortalCookieService = ApplePortalCookieService;
$injector.register("applePortalCookieService", ApplePortalCookieService);
