Source: models/production/session.js

define('application/models/production/session', [
    'rofl/models/api/abstract',
    'application/managers/session',
    'application/models/configuration',
    'rofl/lib/utils',
    'application/models/production/user',
    'antie/runtimecontext',
    'application/managers/feature'
], function (
    Abstract,
    SessionManager,
    ApiConfig,
    Utils,
    User,
    RuntimeContext,
    FeatureManager
) {
    'use strict';

    return Abstract.extend({

        /**
         * Resolves the endpoint.
         *
         * @returns {string} - The endpoint.
         */
        resolveEndpoint: function () {
            return '101/1.2.0/A/nld/smarttv/kpn/USER/SESSIONS';
        },

        /**
         * Validates the response.
         *
         * @param {Object} response - The response.
         * @returns {boolean} Response.
         */
        validateResponse: function (response) {
            return response.resultCode === ApiConfig.RESPONSE_CODES.OK;
        },

        /**
         * Validates the response for DELETE.
         *
         * @param {Object} response - The response.
         * @returns {boolean} Response.
         */
        validateDestroyResponse: function (response) {
            return response.resultCode === ApiConfig.RESPONSE_CODES.OK;
        },

        /**
         * Splits filters.
         *
         * @param {Object} profileData - Profile data.
         * @returns {Array} - Returns array of genres.
         * @private
         */
        _parseGenreFilters: function (profileData) {
            var extendedRatings = Utils.getNested(profileData, 'userPcExtendedRatings');

            if (!extendedRatings) {
                return [];
            }

            return extendedRatings.split(';');
        },

        /**
         * Transforms the response.
         *
         * @param {Object} response - The response.
         * @returns {Object} - Returns the user.
         */
        transformFromCreate: function (response) {
            var user = new User(response.resultObj),
                profileData = Utils.getNested(response, 'resultObj', 'profile', 'profileData'),
                parentalControlParams = {
                    userParentalControl: FeatureManager.getInstance().isParentalEnabled() ? Utils.getNested(profileData, 'userParentalControl') === 'Y' : false,
                    parentalControlLevel: Utils.getNested(profileData, 'userPCLevelEpg') || null,
                    parentalVODControlLevel: Utils.getNested(profileData, 'userPcLevelVod') || null,
                    showLockedTitles: Utils.getNested(profileData, 'showAllTitles') === 'Y',
                    parentalGenres: this._parseGenreFilters(profileData)
                }, sessionManager = SessionManager.getInstance();

            if (FeatureManager.getInstance().isParentalEnabled() && !sessionManager.getUserPin()) {
                sessionManager.setLocalPC(parentalControlParams.userParentalControl);
            }

            RuntimeContext.getCurrentApplication().setUser(user);
            sessionManager.setUserLogin(this);
            sessionManager.setUserPCParams(parentalControlParams);

            return user;
        }
    });
});