'use strict';

/**
 * Creates a new subscription object with the given virtual subscription and unsubscription time.
 *
 * @constructor
 * @param {Number} subscribe Virtual time at which the subscription occurred.
 * @param {Number} unsubscribe Virtual time at which the unsubscription occurred.
 */
function Subscription (start, end) {
  this.subscribe = start;
  this.unsubscribe = end || Number.MAX_VALUE;
}

/**
 * Checks whether the given subscription is equal to the current instance.
 * @param other Subscription object to check for equality.
 * @returns {Boolean} true if both objects are equal; false otherwise.
 */
Subscription.prototype.equals = function (other) {
  return this.subscribe === other.subscribe && this.unsubscribe === other.unsubscribe;
};

/**
 * Returns a string representation of the current Subscription value.
 * @returns {String} String representation of the current Subscription value.
 */
Subscription.prototype.toString = function () {
  return '(' + this.subscribe + ', ' + (this.unsubscribe === Number.MAX_VALUE ? 'Infinite' : this.unsubscribe) + ')';
};

module.exports = Subscription;
