Source: models/production/searchlive.js

define('application/models/production/searchlive', [
    'rofl/models/api/abstract',
    'rofl/lib/utils',
    'application/models/broadcast',
    'application/models/configuration',
    'application/managers/channel'
], function (
    Abstract,
    Utils,
    Broadcast,
    KPNConfig,
    ChannelManager
) {
    'use strict';

    var channelManager = ChannelManager.getInstance();

    return Abstract.extend({

        /**
         * Resolves the endpoint.
         *
         * @param {Object} params - Search parameters.
         * @param {string} params.query - Text to be searched for in the backend.
         * @returns {string} - Resolved endpoint.
         */
        resolveEndpoint: function (params) {
            var sanitizedQuery = encodeURIComponent(params.query),
                channelMap = channelManager.getChannelMap();

            return '101/1.2.0/A/nld/smarttv/kpn/TRAY/SEARCH/PROGRAM?filter_airingTime=now'
                    + '&query=' + sanitizedQuery
                    + '&filter_channelIds=' + channelMap
                    + '&filter_isCatchUp=' + true;
        },

        /**
         * 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') || [];

            return Utils.map(results, function (entry) {
                return new Broadcast(entry);
            });
        },

        /**
         * Validates the read response.
         *
         * @param {Object} response - The read response.
         * @returns {boolean} - True if valid.
         */
        validateReadResponse: function (response) {
            return response.resultCode === KPNConfig.RESPONSE_CODES.OK;
        }
    });
});