//
//  SCAdSequencer.h
//  SCTVOSSDK
//
//  Copyright © 2019 smartclip. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AVKit/AVKit.h>
#import "SCAdSlotController.h"

NS_ASSUME_NONNULL_BEGIN

@class SCAdEnvironment, SCAdSlot, SCAdEvent, SCElementSize;

/**
 * SCAdSequencerDelegate: the sequencer protocol that you need to implemented
 * to be able to react to sequencer state changes, get events from the sdk
 * and to reinsert overscrubbed adSlots.
 */
@protocol SCAdSequencerDelegate <NSObject>

/**
 * Called when the sdk has been reported to be ready
 * for use
 */
- (void)sequencerReady;

/**
 * Called when the content video was scrubbed
 * - Parameter removedAdSlots:          slots that have been removed because they
 *                                      have been overscrubbed by the user
 * - Parameter currentRelativePosition: current relative position (between 0 and 1)
 *                                      of the contentVideo
 * - return value NSArray<SCAdSlot*>* : give back the SCAdSlot objects that you want to
 *                                      reinsert with an actualized relative time (bigger than
 *                                      the currentRelativePosition)
 */
- (NSArray<SCAdSlot*>*)userDidScrub:(NSArray<SCAdSlot*>*)removedAdSlots
            currentRelativePosition:(CGFloat)currentRelativePosition;

/**
 * Called when the content video has finished
 */
- (void)contentVideoFinished;

/**
 * Called when the content video fails for any reason
 */
- (void)contentVideoError:(NSError*)error;

/**
 * Called on for every ScAdInfo type change
 * - Parameter adInfo: current ScAdInfo
 */
- (void)onEventCallbackWithEvent:(SCAdEvent *)event;

/**
 * Called when sequencer has finished its playback sequence
 */
- (void)sequencerFinished;

/**
 * Called when the AVPlayer actually starts video playback
 */
- (void)adStartsPlaybackWith:(NSURL*)url;

///Give back the current player frame and viewMode (normal or fullscreen)
- (nullable SCElementSize*)getPlayerSize;

///Give back the frame of the viewPort and the viewMode (normal or fullscreen)
- (nullable SCElementSize*)getViewportSize;
@end

/**
 * SCAdSequencer: use this class in combination with the SCAdSlot class to define
 *                your sequence of adSlots.
 *                if the user scrubs the content video and thus overscrubs an adSlot
 *                the sequnecer gives you the possibility to reinsert those slots.
 */
@interface SCAdSequencer : NSObject
/// EnvironmentVars for all adSlots, can be changed anytime if you want different settings for
/// different slots
@property (nonatomic, strong) SCAdEnvironment *environmentVars;

/// Delegate that conforms to the SCAdSequencerDelegate protocol
/// Most likely your ViewController
@property (nonatomic, weak) id<SCAdSequencerDelegate> delegate;

/// Default initializer
- (instancetype)initWithAVPlayer:(nonnull AVPlayer*)avPlayer
                         adSlots:(nonnull NSMutableArray*)adSlots
                      contentUrl:(nonnull NSString*)contentURL
                 environmentVars:(nonnull SCAdEnvironment*)environmentVars;
/// Start the sequencer with this function
- (void)startSequencer;

/// Stop the sequencer with this function
- (void)stopSequencer;

///Call this function for a more detailed adInfo
- (void)getAdInfo:(SCAdInfoCompletionBlock)completion;

/// Get your publicAdSlot object here
- (void)getPublicAdSlot:(SCPublicAdSlotCompletionBlock)completion;

///Call this function for a detailed error description
- (void)getAdError:(SCAdErrorCompletionBlock)completion;

///Call this function when the user has pushed the skip button
- (void)skipAd;

///Call this function when you leave your viewController and don´t need the sequencer any more
- (void)cleanup;

///Returns the current time of the current clip
- (double)getCurrentClipTime;

///Returns the duration of the current clip
- (double)getCurrentClipDuration;
@end

NS_ASSUME_NONNULL_END
