//
//  FileNetApi.m
//  AIIM
//
//  Created by gan on 2025/4/15.
//

#import <Foundation/Foundation.h>
#import "FileNetApi.h"
#import <Bugly/Bugly.h>

@implementation FileNetApi

+(void)upLoadWToken:(NSURL *_Nonnull)filePath succ:(GSucc _Nullable )succ fail:(GFail _Nullable )fail{
    [GBaseNetApi.shareInstance upLoadWToken:filePath succ:succ fail:fail];
}

//上传文件
+(void)upLoadDataWToken:(NSData *_Nonnull)data fileName:(NSString *_Nullable)fileName succ:(GSucc _Nullable )succ fail:(GFail _Nullable )fail{
    [GBaseNetApi.shareInstance upLoaddataWToken:data fileName:fileName succ:succ fail:fail];
}

///上传文件（返回上传进度）
+(void)uploadWithFilePath:(NSURL * _Nonnull)filePath thrid:(NSString *_Nullable)thrid progress:(FUploadProgress _Nullable)progress succ:(FSucc _Nullable )succ fail:(FFail _Nullable )fail{
    [GBaseNetApi.shareInstance uploadWithFilePath:filePath thrid:thrid progress:^(NSString * _Nullable thrid, NSProgress * _Nullable uploadProgress) {
        NSLog(@"uploadWithFilePath: %lld %@", 100 * uploadProgress.completedUnitCount / uploadProgress.totalUnitCount, @" %");
        if(progress){
            progress(thrid,uploadProgress);
        }
        else{
        }
        
    } succ:^(int code, NSString * _Nullable thrid, NSDictionary * sdic) {
        [Bugly reportException:[NSException exceptionWithName:@"文件传输成功" reason:[NSString stringWithFormat:@"%@",sdic] userInfo:nil]];
        if(succ){
            succ(code,thrid,sdic);
        }
    } fail:^(NSString * _Nullable thrid, NSError * _Nonnull error) {
        [Bugly reportException:[NSException exceptionWithName:@"文件传输失败：" reason:[NSString stringWithFormat:@"%@",error] userInfo:nil]];
        if(fail){
            fail(thrid,error);
        }
    }];
//    [GBaseNetApi.shareInstance uploadWithFilePath:filePath thrid:thrid progress:
//                                             succ:succ fail:fail];
}

///上传文件（返回上传进度）
+(void)OSSuploadWithFilePath:(NSURL * _Nonnull)filePath thrid:(NSString *_Nullable)thrid progress:(FUploadProgress _Nullable)progress succ:(FSucc _Nullable )succ fail:(FFail _Nullable )fail{
    [GBaseNetApi.shareInstance uploadWithFilePathOSS:filePath thrid:thrid progress:^(NSString * _Nullable thrid, NSProgress * _Nullable uploadProgress) {
        NSLog(@"uploadWithFilePath: %lld %@", 100 * uploadProgress.completedUnitCount / uploadProgress.totalUnitCount, @" %");
        if(progress){
            progress(thrid,uploadProgress);
        }
    } succ:^(int code, NSString * _Nullable thrid, NSDictionary * sdic) {
        [Bugly reportException:[NSException exceptionWithName:@"文件传输成功" reason:[NSString stringWithFormat:@"%@",sdic] userInfo:nil]];
        if(succ){
            succ(code,thrid,sdic);
        }
    } fail:^(NSString * _Nullable thrid, NSError * _Nonnull error) {
        [Bugly reportException:[NSException exceptionWithName:@"文件传输失败：" reason:[NSString stringWithFormat:@"%@",error] userInfo:nil]];
        if(fail){
            fail(thrid,error);
        }
    }];
//    [GBaseNetApi.shareInstance uploadWithFilePath:filePath thrid:thrid progress:
//                                             succ:succ fail:fail];
}

+(void)uploadWithFilePaths:(NSArray <NSURL *>*_Nonnull)filePaths thrid:(NSString *_Nullable)thrid succ:(FSucc _Nullable )succ fail:(FFail _Nullable )fail{
    [GBaseNetApi.shareInstance uploadWithFilePath:filePaths thrid:thrid succ:succ fail:fail];
}

+(void)downLoadWToken:(NSURL *_Nonnull)filePath thrid:(NSString *_Nullable)thrid succ:(GSucc _Nullable )succ fail:(GFail _Nullable )fail{
    [GBaseNetApi.shareInstance downLoadFileWToken:filePath thrid:thrid succ:succ fail:fail];
}

//取消上传
+(void)stopUploadTanck:(NSString *_Nullable)thrid{
    NSLog(@"stopUploadTanck-------------1");
    [GBaseNetApi.shareInstance stopUploadTanck:thrid];
}

@end
