Source: models/production/channels.js

define('application/models/production/channels', [
    'application/models/channels',
    'rofl/lib/utils',
    'application/models/channel',
    'application/models/configuration'
], function (
    Abstract,
    Utils,
    Channel,
    KPNConfiguration
) {
    'use strict';

    return Abstract.extend({

        /**
         * Resolves the endpoint.
         *
         * @returns {string} - The endpoint in string.
         */
        resolveEndpoint: function () {
            var endpoint = '101/1.2.0/A/nld/smarttv/kpn/TRAY/LIVECHANNELS?dfilter_package=subscription' +
                '&maxResults=10000&from=0&to=10000&filter_channelType=EXTENDED&dfilter_channels=subscription';

            return endpoint;
        },

        /**
         * Transforms API data into the abstract model data.
         *
         * @param  {Object} response - The data object gotten from the API.
         * @returns {Object} - The filled model instance.
         */
        transformFrom: function (response) {
            var results = Utils.getNested(response, 'resultObj', 'containers') || [],
                excludedChannels = [],
                channels = [];

            Utils.each(results, function (entry) {
                if (entry.metadata.includedChannels) {
                    Utils.each(entry.metadata.includedChannels, function (channel) {
                        excludedChannels.push(channel.channelId);
                    });
                }
            });

            Utils.each(results, function (entry) {
                if (excludedChannels.indexOf(entry.metadata.channelId) === -1) {
                    KPNConfiguration.setChannelMap(entry.metadata.channelId, entry.metadata.orderId);
                    channels.push(new Channel(entry)); // Channels should be index 1 based.
                }
            });
            return channels;
        },

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