local Rx = require 'Rx'

local Recorded = Rx.testing.Recorded
local Subscription = Rx.testing.Subscription

--------------------------------------------------------------------------------

local ReactiveTest = {

    created = 100,
        -- Default virtual time used for creation of observable sequences in unit tests.

    subscribed = 200,
        -- Default virtual time used to subscribe to observable sequences in unit tests.

    disposed = 1000,
        -- Default virtual time used to dispose subscriptions in unit tests.

}

--------------------------------------------------------------------------------

function ReactiveTest.onNext(ticks, ...)

    if type(ticks) ~= 'number' then
        error("ReactiveTest.onNext: ticks arguments must be a number", 2)
    end

    local firstValue = (...)
    if type(firstValue) == 'function' then
        error("predicate form of ReactiveTest.onNext unimplemented", 2)
    else
        return Recorded(ticks, Rx.Notification.createOnNext(...))
    end

end

--------------------------------------------------------------------------------

function ReactiveTest.onError(ticks, ...)

    if type(ticks) ~= 'number' then
        error("ReactiveTest.onError: ticks arguments must be a number", 2)
    end

    local firstValue = (...)
    if type(firstValue) == 'function' then
        error("predicate form of ReactiveTest.onError unimplemented", 2)
    else
        return Recorded(ticks, Rx.Notification.createOnError(...))
    end

end

--------------------------------------------------------------------------------

function ReactiveTest.onCompleted(ticks)

    if type(ticks) ~= 'number' then
        error("ReactiveTest.onCompleted: ticks arguments must be a number", 2)
    end

    return Recorded(ticks, Rx.Notification.createOnCompleted())

end

--------------------------------------------------------------------------------

function ReactiveTest.subscribe(startTime, endTime)

    if type(startTime) ~= 'number' then
        error("ReactiveTest.onCompleted: startTime arguments must be a number", 2)
    end

    if type(endTime) ~= 'number' then
        error("ReactiveTest.onCompleted: endTime arguments must be a number", 2)
    end

    return Subscription(startTime, endTime)

end

--------------------------------------------------------------------------------

return ReactiveTest
