//
//  NimbleMTX.h
//  NimbleMTX
//
//  Created by Machine Union (dev361) on 2012-11-28.
//  Copyright (c) 2012 Electronic Arts. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <NimbleBase/NimbleComponent.h>
#import "NimbleMTXTransaction.h"
#import "NimbleMTXCatalogItem.h"

#define NIMBLE_COMPONENT_ID_MTX @"com.ea.nimble.mtx"

typedef enum
{
    NIMBLE_MTX_PROMOTED_PAYMENT_DELAY,
    NIMBLE_MTX_PROMOTED_PAYMENT_ACKNOWLEDGED
} NimbleMTXPromotedPaymentAction;

typedef enum
{
	NIMBLE_MTX_STORE_PROMOTION_VISIBILITY_DEFAULT,
	NIMBLE_MTX_STORE_PROMOTION_VISIBILITY_HIDE,
	NIMBLE_MTX_STORE_PROMOTION_VISIBILITY_SHOW
} NimbleMTXStorePromotionVisibility;

typedef void (^NimbleMTXTransactionCallback)(id<NimbleMTXTransaction> transaction);
typedef void (^NimbleMTXRefreshReceiptCallback)(NimbleError* error);
typedef NimbleMTXPromotedPaymentAction (^NimbleMTXPromotedPaymentCallback)(NSString* sku);
typedef void (^NimbleMTXPromotedItemsCallback)(NSArray<NSString *>* skus, NimbleError* error);
typedef void (^NimbleMTXCompletionCallback)(NimbleError* error);
typedef void (^NimbleMTXStorePromotionVisibilityCallback)(NimbleMTXStorePromotionVisibility visibility, NimbleError* error);

#define NIMBLE_NOTIFICATION_MTX_REFRESH_CATALOG_FINISHED @"nimble.notification.mtx.refreshcatalogfinished"
#define NIMBLE_NOTIFICATION_MTX_RESTORE_PURCHASED_TRANSACTIONS_FINISHED @"nimble.notification.mtx.restorepurchasedtransactionsfinished"
#define NIMBLE_NOTIFICATION_MTX_TRANSACTIONS_RECOVERED @"nimble.notification.mtx.transactionsrecovered"

/*
 * MTX module
 */
@protocol NimbleMTX <NimbleComponent>

- (NimbleError*)purchaseItem:(NSString*)sku unverifiedReceiptReceivedCallback:(NimbleMTXTransactionCallback)unverifiedReceiptReceivedCallback purchaseCompleteCallback:(NimbleMTXTransactionCallback)purchaseCompleteCallback metadata:(NSString*)metadata;

- (NimbleError*)itemGranted:(NSString*)transactionId itemType:(NimbleMTXItemType)itemType callback:(NimbleMTXTransactionCallback)callback;

// Only call finalizeTransaction on transactions that are completely finished, since they will be gone forever once this is called,
// unless it can be recovered with restorePurchasedTransactions. If there is a verification error or something that occurs after
// the purchase is complete, the transaction should be resumed with resumeTransaction to retry it from the point of failure.
- (NimbleError*)finalizeTransaction:(NSString*)transactionId callback:(NimbleMTXTransactionCallback)callback;

- (void)restorePurchasedTransactions;

- (NSArray*)getPurchasedTransactions;

- (NSArray*)getPendingTransactions;

- (NSArray*)getRecoveredTransactions;

- (NimbleError*)resumeTransaction:(NSString*)transactionId unverifiedReceiptReceivedCallback:(NimbleMTXTransactionCallback)unverifiedReceiptReceivedCallback purchaseCompleteCallback:(NimbleMTXTransactionCallback)purchaseCompleteCallback itemGrantedCallback:(NimbleMTXTransactionCallback)itemGrantedCallback finalizeCallback:(NimbleMTXTransactionCallback)finalizeCallback;

- (void)refreshAvailableCatalogItems;

- (NSArray*)getAvailableCatalogItems;

- (void)refreshReceiptForAllTransactions:(NimbleMTXRefreshReceiptCallback)refreshReceiptCallback;

- (void)registerPromotedPaymentHandler:(NimbleMTXPromotedPaymentCallback)promotedPaymentCallback;

- (void)fetchStorePromotionOrder:(NimbleMTXPromotedItemsCallback)promotedItemsCallback;

- (void)updateStorePromotionOrder:(NSArray<NSString *>*)skus completionCallback:(NimbleMTXCompletionCallback)callback;

- (void)fetchStorePromotionVisibility:(NSString*)sku visibilityCallback:(NimbleMTXStorePromotionVisibilityCallback)callback;

- (void)updateStorePromotionVisibility:(NSString*)sku visibility:(NimbleMTXStorePromotionVisibility)visibility completionCallback:(NimbleMTXCompletionCallback)callback;

@end

@interface NimbleMTX : NSObject

+ (id<NimbleMTX>)getComponent;

@end
