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

#include "config.h"

#if ENABLE(RMAI)

#include "MOMException.h"
#include "MOMScheduledRecording.h"

#include "JSMOMScheduledRecording.h"

extern "C" {
#include "layers.h"
#include "cdf/mom_recording.h"
}

using namespace JSC;

namespace WebCore {
    
JSValue JSMOMScheduledRecording::startPadding(ExecState* exec) const
{
    MOMScheduledRecording& imp = static_cast<MOMScheduledRecording&>(wrapped());
    int padding = mom_recording_get_start_padding(imp.itemAsRecording());
    if (padding != -1)
        return jsNumber(padding);
    return jsUndefined();
}

void JSMOMScheduledRecording::setStartPadding(ExecState* exec, JSValue value)
{
    MOMScheduledRecording& imp = static_cast<MOMScheduledRecording&>(wrapped());
    mom_recording_set_start_padding(imp.itemAsRecording(), !value ? -1 : value.toInt32(exec));
}

JSValue JSMOMScheduledRecording::endPadding(ExecState* exec) const
{
    MOMScheduledRecording& imp = static_cast<MOMScheduledRecording&>(wrapped());
    int padding = mom_recording_get_end_padding(imp.itemAsRecording());
    if (padding != -1)
        return jsNumber(padding);
    return jsUndefined();
}

void JSMOMScheduledRecording::setEndPadding(ExecState* exec, JSValue value)
{
    MOMScheduledRecording& imp = static_cast<MOMScheduledRecording&>(wrapped());
    mom_recording_set_end_padding(imp.itemAsRecording(), !value ? -1 : value.toInt32(exec));
}

JSValue JSMOMScheduledRecording::remove(ExecState* exec)
{
    MOMScheduledRecording& imp = static_cast<MOMScheduledRecording&>(wrapped());

    MDARemoveReason reason = MDA_REMOVE_THIS;
    if (exec->argumentCount() > 0)
        reason = static_cast<MDARemoveReason>(exec->argument(0).toInt32(exec));

    mom_error err = mom_recording_remove(imp.itemAsRecording(), reason);
    ExceptionCode ec;
    MOMException::setFromMOMError(err, ec);
    setDOMException(exec, ec);

    return jsNull();
}
    
} // namespace WebCore

#endif // ENABLE(RMAI)
