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

#warning 文件夹下载只需数据库文件表现fid和id和serverpath, 下载不需要文件夹, 文件夹ui表现形式由数据库体现.
#import <Foundation/Foundation.h>
#import "CSFileModel.h"
typedef enum {

    DownUpModelDown = 0,
    DownUpModelUp   = 1
    
}DownUpModel;

typedef enum {
//    FileSourcePhotoAlbum, //相册
    FileSourceFileLocal,//一般存储路径,为我的文件文件夹 --> fileType
    FileSourceCSCloud //云盘文件夹
    
}FileSource;

typedef enum {

    FileTypeImage  = 2,//如果fileSource为local,则需要此参数,full path不同.
    FileTypeOther  = 3,//
    
}FileType;

typedef enum {
    
    DownUpStatusWait    = 1,//默认为排队等待.
    DownUpStatusDoing   = 2,
    DownUpStatusPause   = 3,//Pause->恢复doing时判断是否有其他进行,是则=wait.
    DownUpStatusSuccess = 4,
    DownUpStatusFailure = 5,
    DownUpStatusDelete  = 6//任务删除=数据库删除
    
}DownUpStatus;



/**
 *  文件上传下载数据库模型, FMDB独立管理.
 */
@interface CSFileDownUpModel : NSObject

//命名待修正,取消db字段,新增uuid的目的:可能多个model共享同一个task下的model.
typedef void (^DownloadProgressUIBlock)(NSInteger receivedSize, NSInteger expectedSize, CGFloat progress,NSString *router,CSFileDownUpModel *fileDownUpModel,NSString *uuid);
typedef void (^DownloadSuccessUIBlock)(NSInteger receivedSize,NSString *localRouter,CSFileDownUpModel *fileDownUpModel,NSString *uuid);
typedef void (^DownloadFailedUIBlock)(NSString* errMessage,CSFileDownUpModel *fileDownUpModel,NSString *uuid);

typedef void (^CSUploadProgressUIBlock)(double progress,NSInteger sendedSize, CSFileDownUpModel *fileDownUpModel,NSString *uuid);
typedef void (^CSUploadSuccessUIBlock)(NSString* url,long long fileSize,CSFileDownUpModel *fileDownUpModel,NSString *uuid);
typedef void (^CSUploadFailedUIBlock)(NSString* errMessage,CSFileDownUpModel *fileDownUpModel,NSString *uuid);

@property (nonatomic , copy) NSString *sid;
@property (nonatomic , copy) NSString *pid;
@property (nonatomic , copy) NSString *delflag;
@property (nonatomic , copy) NSString *ext;
@property (nonatomic , assign) NSInteger type;
@property (nonatomic , assign) BOOL isdir;
@property (nonatomic , copy) NSString *md5;
@property (nonatomic , copy) NSString *name;
@property (nonatomic , assign) NSInteger size;
@property (nonatomic , copy) NSString *user_id;
@property (nonatomic , copy) NSString *serverFullPath;
@property (nonatomic , copy) NSString *path;//点击文件夹下载时相对当前文件夹的位置

/**
 *  上传还是下载
 */
@property (nonatomic , assign) DownUpModel downUpType;

/**
 *  下载地址(是否需要存储?每次上传下载的时候都要重新请求获取地址.)
 */
//@property (nonatomic , copy) NSString *downLoadUrl;
//
///**
// *  上传地址
// */
//@property (nonatomic , copy) NSString *upLoadUrl;
/**
 *  进行中还是下载
 */
@property (nonatomic , assign) DownUpStatus downUpStatus;

@property (nonatomic , assign) FileSource fileSouce;

@property (nonatomic , assign) FileType fileType;
/**
 *  文件目录层->localRootPath
 */
@property (nonatomic , assign) NSInteger file_category;//服务端的full_server_path 有几个path就有多少count-1.如果/A/B/a.xxx

/**
 *  操作时间
 */
@property (nonatomic , assign) NSInteger downUpTimeStamp;

/**
 *  唯一标识
 */
@property (nonatomic , copy) NSString *downUpUUID;//由时间戳和md5生成.

/**
 *  上传或者下载进度,bit
 */
@property (nonatomic , assign) NSInteger downUpSize;

/**
 *  本地路径,如果有的话
 */
@property (nonatomic , copy) NSString *localRootPath;//重要参数,ui展示路径使用.
//顺序:获取localpath = nil的,找到isdir的文件夹后,点击后查询路径是上一个文件夹的,如此递归...


/**
 *  队列专用,不存储
 */
@property (nonatomic , strong) CSFileDownUpModel *lastFileDownUpModel;

@property (nonatomic , strong) CSFileDownUpModel *nextFileDownUpModel;

/**
 *  当为文件夹时,所有的子文件模型.,数据库查询时赋值返回. 不存储.
 */
@property (nonatomic , strong) NSArray *subFileDownUpModels;

/**
 *  model 下的回调.针对文件夹下载的优化.不存储.
 */
@property (nonatomic, strong)DownloadProgressUIBlock downloadProgressBlock;
@property (nonatomic, strong)DownloadSuccessUIBlock downloadSuccessBlock;
@property (nonatomic, strong)DownloadFailedUIBlock downloadFailedBlock;

@property (nonatomic, strong)CSUploadSuccessUIBlock uploadSuccessBlock;
@property (nonatomic, strong)CSUploadFailedUIBlock uploadFailedBlock;
@property (nonatomic, strong)CSUploadProgressUIBlock uploadProgressBlock;

//主要还是下载.
+ (CSFileDownUpModel *)csfileDownupModelWithfileModel:(CSFileModel *)fileModel downUpType:(DownUpModel)downupType downUpStatus:(DownUpStatus)downUpStatus fileSource:(FileSource)fileSource fileType:(FileType)fileType  localRootPath:(NSString *)localRootPath file_category:(NSInteger)file_category downUpTimeStamp:(NSDate *)downUpTimeStamp downUpUUID:(NSString*)downUpUUID downUpSize:(NSInteger)downUpSize;

//主要还是上传(上传时会选择云盘路径)
+ (CSFileDownUpModel *)csfileDownupModelWithPid:(NSString *)pid Ext:(NSString *)ext type:(NSInteger)type md5:(NSString *)md5 name:(NSString *)name serverFullPath:(NSString *)serverFullPath path:(NSString *)path size:(NSInteger)size user_id:(NSString *)user_id downUpType:(DownUpModel)downupType downUpStatus:(DownUpStatus)downUpStatus fileSource:(FileSource)fileSource fileType:(FileType)fileType  localRootPath:(NSString *)localRootPath file_category:(NSInteger)file_category downUpTimeStamp:(NSDate *)downUpTimeStamp downUpUUID:(NSString*)downUpUUID downUpSize:(NSInteger)downUpSize;

//包一层上传下载请求地址..
@end
