/** @file JSMOMChannelManagerCustom.cpp
 *
 * Copyright (C) Espial Limited 2014 - Company confidential - All rights reserved.
 *
 */

#include "config.h"

#if ENABLE(RMAI)

#include "MOMStringCollection.h"
#include "MOMException.h"
#include "MOMChannelManager.h"

#include "UtilsMOM.h"

#include "JSMOMChannelManager.h"
#include "MOMChannelManager.h"
#include "JSMOMContentList.h"
#include "MOMContentList.h"

extern "C" {
#include "layers.h"
#include "cdf/mom_channel_list.h"
#include "cdf/mom_channel_list_all.h"
#include "cdf/mom_channel_filter.h"
}

using namespace JSC;

namespace WebCore {
    
JSValue JSMOMChannelManager::createFilteredList(ExecState* exec)
{
    MOMChannelManager& imp = static_cast<MOMChannelManager&>(wrapped());
    int argc = exec->argumentCount();

    int blocked = argc >= 1 && exec->argument(0).isBoolean() ? exec->argument(0).toBoolean(exec) : -1;
    int favourite = argc >= 2 && exec->argument(1).isBoolean() ? exec->argument(1).toBoolean(exec) : -1;
    int hidden = argc >= 3 && exec->argument(2).isBoolean() ? exec->argument(2).toBoolean(exec) : -1;
    int in_guide = argc >= 4 && exec->argument(3).isBoolean() ? exec->argument(3).toBoolean(exec) : -1;

    mom_channel_list mcl;
    mom_error err = mom_channel_list_all_create_filtered( blocked, favourite, hidden, in_guide, &mcl );

    if (err)
    {
        ExceptionCode ec;
        MOMException::setFromMOMError(err, ec);
        setDOMException(exec, ec);
        return jsUndefined();
    }
    
    mom_content_item_set_readonly((mom_content_item)mcl);
    return toJS(exec, globalObject(), MOMContentItem::createAdopt(imp.scriptExecutionContext(), (mom_content_item)mcl));
}

} //namespace WebCore

#endif // ENABLE(RMAI)
