//
//  EGIAPKeyChainStore.h
//  EGirl
//
//  Created by donglyu on 2020/6/24.
//  Copyright © 2020 EGirl. All rights reserved.
//

#import <Foundation/Foundation.h>
//#import <UICKeyChainStore/UICKeyChainStore.h>
#import "UICKeyChainStore.h"
#import "IapModels.h"


NS_ASSUME_NONNULL_BEGIN
static NSString *const KeychainServiceKey = @"gg.epal.lab.keychain";
static NSString *const KeychainServicePreStoreKey = @"gg.epal.lab.keychian.prestore";

@interface EGIAPKeyChainStore : UICKeyChainStore


- (instancetype)initWithService:(NSString *)service Group:(nullable NSString *)group;


/// 持久化新的模型
- (void)SavePaymentTransactionModel:( NSArray <PaymentTransactionModel *>*)models forUserId:(NSInteger)userId;

/// 移除某个订单的持久化
- (void)DeletePaymentTransactionModelWithTransactionId:(NSString *)transactionId forUserId:(NSInteger)userId;

/// 票据验证成功，移除持久化
//- (void)DeletePaymentTransactionModelWithTransactionId:(NSString *)transactionId TradeNo:(NSString *)tradeNo ForUserId:(NSInteger)userId;

/// 清理所有空transactionId的数据
- (void)ClearAllEmptyTransactionIdData:(NSInteger)userId;

/// 根据 transactionId 找到之前持久化的其他信息
- (PaymentTransactionModel *)FindPaymentTransactionModelWithTransactionId:(NSString *)transactionId forUserId:(NSInteger)userId;

/// 某个userId下的所有持久化数据
- (NSMutableArray <PaymentTransactionModel *> *)FetchAllTransactionModelsForUser:(NSInteger)userId error:(NSError *__autoreleasing  _Nullable *)error;


#pragma mark - pre store part. 兜底方案. 持续缓存product和tradeId的对应关系

- (void)StorePreProduct:(NSString *)productId TradeId:(NSString *)tradeId;

- (BOOL)FindAndMatchTradeToStartVerifyByProudctId:(NSString *)productId BindTransactionId:(NSString *)transactionId ForUserId:(NSInteger)userId;

@end

NS_ASSUME_NONNULL_END
