//
//  CloudStorageDB.h
//  zhuxun
//
//  Created by winsoft on 17/6/22.
//
//

#import <Foundation/Foundation.h>
#import "CSFileModel.h"
#import "CSFileDownUpModel.h"
#define kCloudStorageDB [CloudStorageDB shareInstance]
@interface CloudStorageDB : NSObject

+ (instancetype)shareInstance;


- (void)addcsFiletoDB:(CSFileModel *)csFile;//插入前判断是否存在,如果存在,则更新.
- (void)addcsFilestoDB:(NSArray *)csFilesArray;

/**
 *   /外部调用前请自身判断是否由相同的数据存在.
 *
 *  @param csDownUpFile add one db.
 */
- (void)addCSDownUpFileToDB:(CSFileDownUpModel *)csDownUpFile;
- (void)addCSDownUpFilesToDB:(NSArray *)csDownUpFileToDBArray downUpModel:(DownUpModel)downUpModel;


- (void)getAllCloudFilesWithPid:(NSString *)pid resultBlock:(void(^)(NSArray *result))resultBlock;//1
- (void)getFileModelWithFileMD5:(NSString *)md5 resultBlock:(void(^)(CSFileModel *csFileModel))resultBlock;

- (void)getCSDownUpFileWithMD5:(NSString *)md5 downUpModel:(DownUpModel)downUpModel resultBlock:(void(^)(NSArray *csFileModels))resultBlock;
/**
 *  文件上传时选择路径时用(舍弃(无缓存下不能使用,使用rename检测接口)) 及 文件下载时判断是否需要新下载判断
 *
 */
- (void)getCSDownUpFileWithMD5:(NSString *)md5 pid:(NSString *)pid name:(NSString *)name downUpModel:(DownUpModel)downUpModel resultBlock:(void(^)(CSFileDownUpModel *csFileModel))resultBlock;



- (void)getCSDownUpFileWithUUID:(NSString *)downUpUUID downUpModel:(DownUpModel)downUpModel resultBlock:(void(^)(CSFileDownUpModel *csFileModel))resultBlock;

//数据库中获取所有目标的uuid的文件
- (void)getCSDownUpFilesWithUUIDs:(NSArray *)downUpUUIDs downUpModel:(DownUpModel)downUpModel resultBlock:(void(^)(NSArray *csFileModels))resultBlock;
//获取md5 不同,但name相同的情况.上层判断后再进行此判断
- (void)getCSDownUpFileSameNameDifMd5WithMD5:(NSString *)md5 name:(NSString *)name localPath:(NSString *)localPath downUpModel:(DownUpModel)downUpModel resultBlock:(void(^)(NSInteger sameNameFileCount))resultBlock;

//获取正在等待或下载的文件
- (void)getProcessCSDownUpFileWithMD5:(NSString *)md5 name:(NSString *)name downUpModel:(DownUpModel)downUpModel resultBlock:(void(^)(NSArray *downUpModels))resultBlock;

//获取所有数据库中等待或者进行中的文件.首次启动恢复下载.
- (void)getAllProcessOrWaitFileWithResultBlock:(void(^)(NSArray *downModels,NSArray *upModels))resultBlock;
//获取文件夹下所有子文件(递归所有)//isdir = 0 文件, 1 文件夹, 2 = 所有
- (void)getAllCSDownUpFilesFoldersWithPid:(NSString *)pid isdir:(NSInteger)isDir downUpModel:(DownUpModel)downUpModel resultBlock:(void(^)(NSArray *downUpModels))resultBlock;

//获取当前文件夹下 所有文件是否下载/上传成功
- (void)getFolderFilesDownUpStatusWithPid:(NSString *)pid downUpModel:(DownUpModel)downUpModel resultBlock:(void(^)(DownUpStatus downUpStatus))resultBlock;

#warning 2017-07-04
/**
 *  文件夹下载时判断当前category = 0 的同id同name的文件夹是否存在.
 */
- (void)getCSDownUpFolderWithID:(NSString *)sid isdir:(BOOL)isdir name:(NSString *)name category:(NSInteger)category  downUpModel:(DownUpModel)downUpModel  resultBlock:(void(^)(CSFileDownUpModel *csFileModel))resultBlock;
/**
 *  文件夹下载时新建了cagegory = 0的文件,如果之前sid有成功的,则设置下载状态为成功
 *
 *  @param sid         <#sid description#>
 *  @param downUpModel <#downUpModel description#>
 *  @param resultBlock <#resultBlock description#>
 */
- (void)getCSDownUpFolderAndSetSameStatusWithID:(NSString *)sid downUpModel:(DownUpModel)downUpModel;

/**
 *  获取一级子文件所有文件
 *
 *  @param pid         pid
 *  @param resultBlock callBack
 */
- (void)getSubFileFolderDownFileWithPid:(NSString *)pid ResultBlock:(void(^)(NSArray *result))resultBlock;
- (void)getSubFileFolderDownSuccessFileWithPid:(NSString *)pid ResultBlock:(void(^)(NSArray *result))resultBlock;
- (void)getSubFileFolderDownUnFinishedFileWithPid:(NSString *)pid ResultBlock:(void(^)(NSArray *result))resultBlock;

- (void)getSubFileFolderUpFileWithPid:(NSString *)pid ResultBlock:(void(^)(NSArray *result))resultBlock;
- (void)getSubFileFolderUpSuccessFileWithPid:(NSString *)pid ResultBlock:(void(^)(NSArray *result))resultBlock;
- (void)getSubFileFolderUpUnFinishedFileWithPid:(NSString *)pid ResultBlock:(void(^)(NSArray *result))resultBlock;


//delete
- (void)deleteCSFileToDB:(CSFileModel *)csFile;

- (void)deleteCSDownUpFiles:(NSArray *)csFiles downUpType:(DownUpModel)downUpModel ResultBlock:(void(^)(NSArray *files))resultBlock; ;

//update
- (void)updateCSFiletoDB:(CSFileModel *)csFile;

/**
 *  移动文件(文件夹)更新数据库
 *
 *  @param csFileSids source files/folders ids
 *  @param pid        target folder id
 */
- (void)updateCSFilestoDB:(NSArray*)csFileSids targetid:(NSString*)pid;
//可更新所有同样的文件..
- (void)updateCSDownUpFileStatusWithCSFileDownUpModel:(CSFileDownUpModel *)csFileDownUpModel;

- (void)updateCSDownUpFileStatusWithCSFileDownUpModels:(NSArray *)csFileDownUpModels downUpType:(DownUpModel)downUpType downUpStatus:(DownUpStatus)downUpStatus;
//上传成功后更新sid
- (void)updateCSDownUpFileIDWithCSFileDownUpModel:(CSFileDownUpModel *)csFileDownUpModel sid:(NSString *)sid;

//重名的不同文件,修改本地存放地址
- (void)updateCSDownUpFileLocalPathWithCSFileDownUpModel:(CSFileDownUpModel *)csFileDownUpModel newLocalPath:(NSString *)newLocalPath;


@end
