//
//  ZYJQNBaseUpload.m
//  ZYJQiniuSDK
//
//  Created by WorkSpace_Sun on 2020/4/19.
//  Copyright © 2020 Qiniu. All rights reserved.
//

#import "ZYJQNBaseUpload.h"

@interface ZYJQNBaseUpload ()

@end

@implementation ZYJQNBaseUpload

- (void)run {
    // rewrite by subclass
}

- (void)collectHttpResponseInfo:(ZYJQNHttpResponseInfo *)httpResponseInfo fileOffset:(uint64_t)fileOffset {
    
    ZYJQNZonesInfo *zonesInfo = [self.config.zone getZonesInfoWithToken:self.token];
    NSString *targetRegionId = [zonesInfo getZoneInfoRegionNameWithType:ZYJQNZoneInfoTypeMain];
    NSString *currentRegionId = [zonesInfo getZoneInfoRegionNameWithType:self.currentZoneType];
    
    [Collector addRequestWithType:self.requestType httpResponseInfo:httpResponseInfo fileOffset:fileOffset targetRegionId:targetRegionId currentRegionId:currentRegionId identifier:self.identifier];
    
    uint64_t bytesSent;
    if (self.requestType == ZYJQNRequestType_mkblk || self.requestType == ZYJQNRequestType_bput) {
        if (httpResponseInfo.hasHttpResponse) {
            bytesSent = httpResponseInfo.bytesTotal;
        } else {
            bytesSent = 0;
        }
        [Collector append:ZYJCK_blockBytesSent value:@(bytesSent) identifier:self.identifier];
    } else {
        bytesSent = httpResponseInfo.bytesSent;
    }
    
    [Collector append:ZYJCK_totalBytesSent value:@(bytesSent) identifier:self.identifier];
}

- (void)collectUploadQualityInfo {
    
    ZYJQNZonesInfo *zonesInfo = [self.config.zone getZonesInfoWithToken:self.token];
    NSString *targetRegionId = [zonesInfo getZoneInfoRegionNameWithType:ZYJQNZoneInfoTypeMain];
    NSString *currentRegionId = [zonesInfo getZoneInfoRegionNameWithType:self.currentZoneType];
    [Collector update:ZYJCK_targetRegionId value:targetRegionId identifier:self.identifier];
    [Collector update:ZYJCK_currentRegionId value:currentRegionId identifier:self.identifier];
    [Collector update:ZYJCK_fileSize value:@(self.size) identifier:self.identifier];
}
@end
