define('application/models/production/recordings/recording', [
'rofl/models/api/abstract',
'rofl/lib/utils',
'application/models/configuration',
'application/models/production/recordings/record',
'application/models/production/series',
'application/managers/channel'
], function (
Abstract,
Utils,
KPNConfig,
Record,
Series,
ChannelManager
) {
'use strict';
var channels = ChannelManager.getInstance().getChannelMap();
return Abstract.extend({
/**
* Resolves the endpoint.
*
* @param {Object} params - The parameters.
* @returns {string} - Endpoint.
*/
resolveEndpoint: function (params) {
var endpoint;
switch (params.type) {
case 'series':
endpoint = '101/1.2.0/A/nld/smarttv/kpn/CONTENT/RECORDING/SERIES';
break;
case 'episode':
default:
endpoint = '101/1.2.0/A/nld/smarttv/kpn/CONTENT/RECORDING/EVENT';
}
return endpoint;
},
/**
* Transforms the response.
*
* @param {Object} response - The response.
* @returns {Object} Result.
*/
transformFromCreate: function (response) {
var data = Utils.getNested(response, 'resultObj', 'containers'),
result = {
items: {},
ids: [],
series: {}
};
if (!data || !data.length) {
return null;
}
Utils.each(data, function (item) {
var channelId = item.channel ? item.channel.channelId : item.metadata.channelId,
record;
if (channels.indexOf(channelId) >= 0) {
if (item.layout === 'CONTENT_ITEM') {
record = new Record(item);
result.items[item.metadata.liveContentId] = record;
result.ids.push(item.metadata.liveContentId);
if (!result.series[record.getSeriesId()]) {
result.series[record.getSeriesId()] = new Series(record);
} else {
result.series[record.getSeriesId()].addItem(record);
}
} else {
if (!result.items.length) {
result.items = [];
}
result.items.push(item);
}
}
});
return result;
},
/**
* Validates the response.
*
* @param {Object} response - The response.
* @returns {boolean} - True if valid.
*/
validateResponse: function (response) {
return Utils.getNested(response, 'resultCode') === KPNConfig.RESPONSE_CODES.OK;
}
});
});