local Rx = require 'Rx'

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

local subscriptionPrototype = {

    subscribe = false,
        -- (number) Virtual time at which the subscription occurred

    unsubscribe = false,
        -- (number) Virtual time at which the unsubscription occurred

}

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

function subscriptionPrototype:__init(subscribe, unsubscribe)

    if type(subscribe) ~= 'number' then
        error("Rx.testing.Subscription: start time must be a number", 3)
    end

    if unsubscribe ~= nil and type(unsubscribe) ~= 'number' then
        error("Rx.testing.Subscription: end time must be a number", 3)
    end

    self.subscribe = subscribe
    self.unsubscribe = unsubscribe or 1/0

end

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

function subscriptionPrototype:__eq(other)

    return self.subscribe == other.subscribe and self.unsubscribe == other.unsubscribe

end

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

function subscriptionPrototype:__tostring()

    return string.format("(%s, %s)", tostring(self.subscribe), tostring(self.unsubscribe))

end

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

return Rx.Class('Rx.testing.Subscription', subscriptionPrototype)
