//
//  DONSChangesFeedClient.h
//  DOCore
//
//  Created by Ben Dolman on 8/12/14.
//
//

#import <Foundation/Foundation.h>

@class DOWebClient;
@protocol DONSChangesFeedClientDelegate;

/**
 * Schedules and executes requests to the sync changes feed endpoint.
 */
@interface DONSChangesFeedClient : NSObject

@property (copy, readonly) DOWebClient *webClient;
@property (copy, readonly) NSString *journalID;
@property (assign, readonly) BOOL isActive;
@property (weak, readonly) id<DONSChangesFeedClientDelegate> delegate;
@property (copy, readonly) NSDate *lastCompletionDate;
@property (assign) BOOL scheduledRequestsSuspended;

- (instancetype)initWithWebClient:(DOWebClient *)webClient
                        journalID:(NSString *)journalID
                         delegate:(id<DONSChangesFeedClientDelegate>) delegate;

- (void)scheduleRequestAfterDelay:(NSTimeInterval)delay;

- (void)cancel;

@end


@protocol DONSChangesFeedClientDelegate <NSObject>
@required
- (NSNumber *)changesFeedClientCursorForNextRequest:(DONSChangesFeedClient *)client;
@optional
- (void)changesFeedClient:(DONSChangesFeedClient *)client willBeginRequestWithCursor:(NSNumber *)cursor;
- (void)changesFeedClient:(DONSChangesFeedClient *)client didReceiveResults:(NSArray *)results;
- (void)changesFeedClient:(DONSChangesFeedClient *)client didFinishRequestWithNewCursor:(NSNumber *)newCursor;
- (void)changesFeedClient:(DONSChangesFeedClient *)client didFinishRequestWithError:(NSError *)error;

@end