//
//  CODownloadManager+Reject.m
//  WXQuestion
//
//  Created by hyz on 2019/3/31.
//  Copyright © 2019 中公网校. All rights reserved.
//

#import "CODownloadManager+Reject.h"
#import "CODownloadModel.h"
#import "WXCOUtility.h"
#import "WXCOMacros.h"

@implementation CODownloadManager (Reject)

- (void)showNormalDownloadRejectInfo:(NSMutableArray<CODownloadRejectModel *> *)rejectArray {
    [self showNormalDownloadRejectInfo:rejectArray withPriorityDownlaod:NO];
}

- (void)showNormalDownloadRejectInfo:(NSMutableArray<CODownloadRejectModel *> *)rejectArray
                withPriorityDownlaod:(BOOL)isPriority {
    if (rejectArray == nil || rejectArray.count <= 0) {
        [WXCOUtility showAlertWithMessage:(isPriority == YES ? @"已优先下载" : @"已添加到下载队列，请前往缓存下载查看")];
        return;
    }
    
    NSString *message = @"";
    for (CODownloadRejectModel *model in rejectArray) {
        if (model.reason == DownloadRejectReasonEmptyList ||
            model.reason == DownloadRejectReasonNoNetwork ||
            model.reason == DownloadRejectReasonWWANNetwork) {
            [WXCOUtility showAlertWithMessage:model.description];
            message = nil;
            break;
        } else if (model.reason == DownloadRejectReasonEmptyURL ||
                   model.reason == DownloadRejectReasonUnsupported ||
                   model.reason == DownloadRejectReasonOfflineCode ||
                   model.reason == DownloadRejectReasonPassword ||
                   model.reason == DownloadRejectReasonNoPlayback) {
            if (WXCOStringIsEmpty(message) == YES) {
                message = model.description;
            } else {
                message = [NSString stringWithFormat:@"%@\n%@", message, model.description];
            }
        }
    }
    
    if (WXCOStringIsEmpty(message) == NO) {
        [WXCOUtility showAlertWithMessage:message];
    }
}

@end
