//
//  YSRACEvent.h
//  ReactiveObjC
//
//  Created by Justin Spahr-Summers on 2013-01-07.
//  Copyright (c) 2013 GitHub, Inc. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

/// Describes the type of a YSRACEvent.
///
/// YSRACEventTypeCompleted - A `completed` event.
/// YSRACEventTypeError     - An `error` event.
/// YSRACEventTypeNext      - A `next` event.
typedef NS_ENUM(NSUInteger, YSRACEventType) {
    YSRACEventTypeCompleted,
    YSRACEventTypeError,
    YSRACEventTypeNext
};

/// Represents an event sent by a YSRACSignal.
///
/// This corresponds to the `Notification` class in Rx.
@interface YSRACEvent<__covariant ValueType> : NSObject <NSCopying>

/// Returns a singleton YSRACEvent representing the `completed` event.
+ (YSRACEvent<ValueType> *)completedEvent;

/// Returns a new event of type YSRACEventTypeError, containing the given error.
+ (YSRACEvent<ValueType> *)eventWithError:(nullable NSError *)error;

/// Returns a new event of type YSRACEventTypeNext, containing the given value.
+ (YSRACEvent<ValueType> *)eventWithValue:(nullable ValueType)value;

/// The type of event represented by the receiver.
@property (nonatomic, assign, readonly) YSRACEventType eventType;

/// Returns whether the receiver is of type YSRACEventTypeCompleted or
/// YSRACEventTypeError.
@property (nonatomic, getter = isFinished, assign, readonly) BOOL finished;

/// The error associated with an event of type YSRACEventTypeError. This will be
/// nil for all other event types.
@property (nonatomic, strong, readonly, nullable) NSError *error;

/// The value associated with an event of type YSRACEventTypeNext. This will be
/// nil for all other event types.
@property (nonatomic, strong, readonly, nullable) ValueType value;

@end

NS_ASSUME_NONNULL_END
