//
//  GDBManager.h
//  Pods
//
//  Created by gan on 2025/3/24.
//

#ifndef GDBManager_h
#define GDBManager_h


#endif /* GDBManager_h */
#import "GIMobj.h"

typedef void (^DBFail)(NSString * _Nullable error);
typedef void (^DBSucc)(NSArray * _Nullable array);

@class GDBManager;
@protocol GDBManagerDelegate <NSObject>
@optional
- (void)GDBManagerAction:(NSString *_Nullable)message;
@end


@interface GDBManager : NSObject

+ (GDBManager *_Nonnull)shareInstance;
@property (nonatomic,weak) id <GDBManagerDelegate> delegate;


-(void)replayAllData;


//消息表
-(void)createDatabase:(DBSucc _Nullable )succ fail:(DBFail _Nullable )fail;
-(void)deleteDB;
-(void)createLocalMSGtable:(DBSucc _Nullable )succ fail:(DBFail _Nullable )fail;
-(void)delLocalmsglistTable:(NSString *_Nullable)userid;
-(void)insertLocalmsg:(NSDictionary *_Nonnull)msg succ:(DBSucc _Nullable )succ fail:(DBFail _Nullable )fail;
- (void)batchInsertLocalMessages:(NSArray<NSDictionary *> *_Nullable)messages success:(DBSucc _Nullable)succ failure:(DBFail _Nullable)fail;
//插入数据，存在则替换
-(void)insertRplaceLocalmsg:(NSDictionary *_Nonnull)msg succ:(DBSucc _Nullable )succ fail:(DBFail _Nullable )fail;

-(void)selectLocalmsg:(NSString *_Nonnull)chatId page:(NSInteger)page succ:(DBSucc _Nullable )succ fail:(DBFail _Nullable )fail;
-(void)selectnextmsg:(NSString *_Nonnull)chatId timestp:(NSInteger)timestp succ:(DBSucc _Nullable )succ fail:(DBFail _Nullable )fail;
//删除自己的本地缓存消息
-(void)deleteMyLocalmsg:(NSDictionary *_Nullable)msg;
//删除数据指定消息
-(void)deleteLocalmsg:(NSDictionary *_Nullable)msg;

//删除数据指定聊天窗消息
-(void)deletechatLocalmsg:(NSString *_Nullable)chatId;

//按分类查询消息
-(void)selectLocalmsgType:(NSString *_Nullable)chatId messageType:(NSString *_Nullable)messageType succ:(DBSucc _Nullable )succ fail:(DBFail _Nullable )fail;

//按分类查询下一页消息
-(void)selectNextmsgType:(NSString *_Nullable)chatId messageType:(NSString *_Nullable)messageType timestp:(NSInteger)timestp succ:(DBSucc _Nullable )succ fail:(DBFail _Nullable )fail;
//根据本地时间查询本地消息
-(void)selectLocalmsgWithLocaltime:(NSString *_Nullable)localtime succ:(DBSucc _Nullable )succ fail:(DBFail _Nullable )fail;



//聊天窗表
-(void)createChattable:(DBSucc _Nullable )succ fail:(DBFail _Nullable )fail;
-(void)delchatlistTable:(DBSucc _Nullable )succ fail:(DBFail _Nullable )fail;//删除聊天窗表lcChatlist_
-(void)insertLocalchat:(NSDictionary *_Nonnull)msg succ:(DBSucc _Nullable )succ fail:(DBFail _Nullable )fail;
-(void)selectLocalchats:(NSString *_Nullable)top succ:(DBSucc _Nullable )succ fail:(DBFail _Nullable )fail;
///删除单个聊天
- (void)deleteChatListItem:(NSDictionary *_Nonnull)item succ:(DBSucc _Nullable )succ fail:(DBFail _Nullable )fail;
//聊天窗最后已读时间表
-(void)createLastreadtimetable:(DBSucc _Nullable )succ fail:(DBFail _Nullable )fail;
-(void)insertLastreadtime:(NSDictionary *_Nonnull)msg succ:(DBSucc _Nullable )succ fail:(DBFail _Nullable )fail;
-(void)selectchatLastreadtime:(NSString *_Nonnull)chatId succ:(DBSucc _Nullable )succ fail:(DBFail _Nullable )fail;
//好友群组表

@end
