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

#import "CSFileDownUpModel.h"
#import <MJExtension/MJExtension.h>
@implementation CSFileDownUpModel

- (NSString *)downUpUUID
{
    return self.isdir?[NSString stringWithFormat:@"%@_%@",self.name,self.pid]:[NSString stringWithFormat:@"%@_%@_%@",self.name,self.md5,self.pid];
}

- (void)setName:(NSString *)name
{
    if([name rangeOfString:@"'"].location != NSNotFound){
        
        _name = [name stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
        
    }else _name = name;
    
}

//主要还是下载.
+ (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 *downUpModel = [[CSFileDownUpModel alloc]init];
    
    downUpModel.sid= fileModel.sid;
    downUpModel.pid = fileModel.pid?fileModel.pid:@"0";
    downUpModel.delflag = fileModel.delflag;
    downUpModel.ext = fileModel.ext;
    downUpModel.type = fileModel.type;
    downUpModel.isdir = fileModel.isdir;
    downUpModel.md5 = fileModel.md5;
    downUpModel.name = fileModel.name;
    downUpModel.size = fileModel.size;
    downUpModel.user_id = fileModel.user_id;
    downUpModel.serverFullPath = fileModel.serverFullPath;
    downUpModel.path = fileModel.path;
    
    downUpModel.downUpType = downupType;
    downUpModel.downUpStatus = downUpStatus;
//    if(fileModel.isdir) downUpModel.downUpStatus = DownUpStatusSuccess;//文件夹默认成功状态.
    downUpModel.fileSouce = fileSource;
    downUpModel.fileType = fileType;
    downUpModel.localRootPath = localRootPath;
    downUpModel.file_category = file_category;
    downUpModel.downUpTimeStamp = [[NSDate date]timeIntervalSince1970]*1000;
//    downUpModel.downUpUUID = downUpUUID;
    downUpModel.downUpSize = downUpSize;
    
    downUpModel.downUpUUID =  downUpModel.downUpUUID;
    
    return downUpModel;
}

//主要还是上传(上传时会选择云盘路径,如果转存文件夹的话..)
+ (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
{
    CSFileDownUpModel *downUpModel = [[CSFileDownUpModel alloc]init];
    downUpModel.isdir = NO;
    downUpModel.pid = pid?pid:@"0";
    downUpModel.ext = ext;
    downUpModel.type = type;
    downUpModel.md5 = md5;
    downUpModel.name = name;
    downUpModel.serverFullPath = serverFullPath;
    downUpModel.path = path;
    downUpModel.size = size;//size 外部如果是消息的话是否根据fileutils获取
    downUpModel.user_id = user_id;
    
    downUpModel.downUpType = downupType;
    downUpModel.downUpStatus = downUpStatus;
    downUpModel.fileSouce = fileSource;
    downUpModel.fileType = fileType;
    downUpModel.localRootPath = localRootPath;
    downUpModel.file_category = file_category;
    downUpModel.downUpTimeStamp = [[NSDate date]timeIntervalSince1970]*1000;
//    downUpModel.downUpUUID = [NSString stringWithFormat:@"%ld_%@",downUpModel.downUpTimeStamp,md5];
    downUpModel.downUpSize = downUpSize;
    downUpModel.downUpUUID =  downUpModel.downUpUUID;
    return downUpModel;
}
@end
