/**
 * VCFileTransferProtocol.h: Vacuum
 * Created by Jiří Urbášek on 9/29/12.
 *
 * Copyright (c) 2012, Arat. All rights reserved.
 *
 * This source code can be used only for purposes specified
 * by the given license contract signed by the rightful deputy of Arat.
 * This source code can be used only by the owner of the license.
 *
 * Any disputes arising in respect of this agreement (license) shall be brought
 * before the Municipal Court of Prague.
 */

#import <Foundation/Foundation.h>


extern long kVCFileTransferHeaderTag;
extern long kVCFileTransferFilesTag;
extern long kVCFileTransferTransferConfirmationTag;
extern long kVCFileTransferFileReceivedAckTag;
extern long kVCFileTransferFileReceivingFinishedAckTag;
extern long kVCFileTransferNotificationTokenTag;


typedef NS_ENUM(NSInteger, VCDataReceiverState) {
    VCDataReceiverStateStarted = 0,
    VCDataReceiverStateWaitingForHeaders,
    VCDataReceiverStateReceivedHeaders,
    VCDataReceiverStateWaitingForUserInput,
    VCDataReceiverStateDownloading,
    VCDataReceiverStateFinished,
    VCDataReceiverStateCanceled
};

typedef NS_ENUM(NSInteger, VCDataSenderState) {
    VCDataSenderStateStarted = 0,
    VCDataSenderStateResolving,
    VCDataSenderStateSendingHeaders,
    VCDataSenderStateSendingFiles,
    VCDataSenderStateFinished,
    VCDataSenderStateCanceled
};


@protocol VCTransferableItem;

@interface VCTransferProtocol : NSObject

@property (nonatomic, strong, readonly) NSData *headerDelimiterData;
@property (nonatomic, strong, readonly) NSData *transferFinishedAckData;
@property (nonatomic, strong, readonly) NSData *allowTransferData;
@property (nonatomic, strong, readonly) NSData *denyTransferData;
@property (nonatomic, strong, readonly) NSData *transferConfirmationResponseData;
@property (nonatomic, assign, readonly) NSData *allowNotificationTokenRequestData;
@property (nonatomic, assign, readonly) NSData *denyNotificationTokenRequestData;
@property (nonatomic, strong, readonly) NSString *version;

@property (nonatomic, readonly) id<VCTransferableItem> currentlySendingFile;
@property (nonatomic, readonly) unsigned long long currentlySendedDataLength;

- (NSData *)headerDataFromFiles:(NSArray *)files;
- (NSData *)headerDataForNotificationToken;

@property (nonatomic, readonly) NSArray *receivedFiles;

- (void)receivedHeaderData:(NSData *)data;
- (NSArray *)senderFiles;
- (NSString *)senderDeviceName;
- (NSString *)senderDeviceType;
- (NSString *)senderDeviceID;
- (NSString *)senderProtocolVersion;
- (NSString *)senderApplicationType;
- (NSString *)senderPushNotificationToken;

- (BOOL) requiresNoticationToken;
- (NSDictionary *)notificationTokenFromData:(NSData *)data;

/** Returns data part to be sent. If there is some error, it returns nil and fills in error object */
- (NSData *)filesDataPartError:(NSError **)error;
- (BOOL)hasFilesDataToSend;
- (void)nextFileToSend;

- (NSData *)fileReceivedAckDataForFileAtIndex:(NSInteger)index;
- (NSInteger)indexFromReceivedAckData:(NSData *)data;

@end
