//
//  SCAdSlotController.h
//  SCTVOSSDK
//
//  Copyright © 2018 smartclip. All rights reserved.
//
#import <Foundation/Foundation.h>

@class SCAdInfo, SCAdConfiguration, SCAdEvent, SCPublicAdSlot, SCAdError, SCElementSize;

/// Completionblock that delivers a SCAdInfo object
typedef void (^SCAdInfoCompletionBlock)(SCAdInfo* _Nullable adInfo);
/// Completionblock that delivers a SCPublicAdSlot object
typedef void (^SCPublicAdSlotCompletionBlock)(SCPublicAdSlot* _Nullable publicAdSlot);
/// Completionblock that delivers a SCAdError object
typedef void (^SCAdErrorCompletionBlock)(SCAdError* _Nullable adError);
/**
 * The listener protocol that needs to be implemented by your view controller
 */
@protocol SCAdListener <NSObject>
@required

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

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

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

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

/**
* Returns the rect of the avplayer layer and if it is displayed fullscreen or not
*/
- (nullable SCElementSize*)getPlayerSize;

/**
* Returns the rect of the viewport and if the player is displayed fullscreen or not
*/
- (nullable SCElementSize*)getViewportSize;
@end

/**
* The SCAdSlotController initializes and controls a single AdSlot.
* A valid AdSlot must be inialized from the SCAdSessionController.
*/
@interface SCAdSlotController: NSObject

///Register your SCAdListener here as the delegate of the SCAdSlotController
@property (nonatomic, weak) id<SCAdListener> _Nullable delegate;

///Because the SCAdSlotController holds the AVPlayer, you call this function
///to start playback of your content video
- (void)playContentVideoWith:(nonnull NSString*)url;

/**
* You start the playback of an ad slot with this function
* - Parameter configutation: An instance of SCAdConfiguration
*/
- (void)startAdSlotWith:(nonnull SCAdConfiguration*)configuration;

///Call this function if you leave your view controller while video (or advertisement) playback is still active
- (void)stopAdSlot;

///Cleanup after usage!
- (void)cleanup;

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

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

///Call this function for a more detailed adInfo
- (void)getPublicAdSlot:(nonnull SCPublicAdSlotCompletionBlock)completion;

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

///Returns the current time of the current video
- (double)getCurrentTime;

///Returns the duration of the current video
- (double)getDuration;
@end
