//
//  MVMCoreSessionTimeHandler.h
//  myverizon
//
//  Created by Scott Pfeil on 2/25/14.
//  Copyright (c) 2014 Verizon Wireless. All rights reserved.
//
//  Handles the session timer.

#import <Foundation/Foundation.h>

@class MVMCoreErrorObject;

@interface MVMCoreSessionTimeHandler : NSObject

// The time that we started the last session timer.
@property (assign, nonatomic, readonly) NSTimeInterval timeTimerStarted;

#pragma mark - functions to override

// Can override to provide a time until the warning shows in seconds. Set to 0 if there should be no warning. Default is 0
- (NSTimeInterval)timeUntilWarning;

// Can override to provide a time until the timeout happens in seconds. If there is a warning, then this value is used after the warning happens. Set to 0 if there should be no timeout. Default is 0.
- (NSTimeInterval)timeUntilTimeout;

// Starts the timeout timer. Override to handle what happens on timeout warning. Should call super if want the timeout timer going.
- (void)sessionTimeoutWarning NS_REQUIRES_SUPER;

// Called when the session has timed out. Override to handle what happens on timeout. Should call super. Can be called to force timeout... should never need to call unless simulating timout.
- (void)sessionTimeout:(BOOL)whileInBackground NS_REQUIRES_SUPER;

// Keeps the session alive. A boolean for if we should show the alert if there is an error. Does nothing by default. Can override to do something.
- (void)sendKeepAliveToServer:(BOOL)notifyUserIfError;

// Invalidates the server session and then calls the completion handler. Error may or may not populate. By default this only calls the completion handler, override to invalidate your server session as you see fit then call completion.
- (void)invalidateSession:(void (^ __nullable)(MVMCoreErrorObject * _Nullable error))completion;

#pragma mark - Session timer functions

// Returns the shared instance of this singleton
+ (nullable instancetype)sharedSessionHandler;

// Starts the session timer. Should be called after every response from the server. Happens on the main thread.
- (void)startSessionTimer;

// Should only be used in rare occassions, like on the original wifi screen.
- (void)stopSessionTimer;

// Returns whether the app is in session.
- (BOOL)isAppInSession;

// Resets everything.
- (void)resetState;

@end
