//
//  ERPUtils.m
//  iSales-NPD
//
//  Created by Jack on 2017/2/13.
//  Copyright © 2017年 United Software Applications, Inc. All rights reserved.
//

#import "ERPUtils.h"
#import "AppDelegate.h"
#import "Singleton.h"


@implementation ERPUtils

+ (NSString *)orderStatus:(NSInteger)statusCode {
    
    __block NSString *status = nil;
    
    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    NSDictionary *filter = nil;
    switch (appDelegate.user_type) {
        case USER_ROLE_EMPLOYEE: {
            filter = appDelegate.OrderFilter;
        }
            break;
        case USER_ROLE_CUSTOMER: {
            if ([Singleton sharedInstance].customer_order_type == 0) {
                filter = [Singleton sharedInstance].shop_order_status_filter;
            } else {
                filter = [Singleton sharedInstance].sales_order_status_filter;
            }
        }
            break;
        case USER_ROLE_UNKNOWN: {
            
        }
            
        default:
            break;
    }
    
    [filter enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
        
        if ([obj isKindOfClass:[NSDictionary class]]) {
            NSDictionary *orderStatusDic = (NSDictionary *)obj;
            if ([[orderStatusDic objectForKey:@"value_id"] integerValue] == statusCode) {
                status = [orderStatusDic objectForKey:@"value"];
                *stop = YES;
            }
        }
        
    }];
    
    return status;
}

@end
