//
//  CustomerServicePowerHttpPostCmd+Response.m
//  MobilePortal
//
//  Created by xie on 2024/1/17.
//  Copyright © 2024 yin chen. All rights reserved.
//

#import "CustomerServicePowerHttpPostCmd+Response.h"
#import "CustomerServicePowerHttpPostCmd.h"
#import "CustomerServiceHttpResult.h"


@protocol CustomerServiceHttpResultData;
@interface CustomerServiceHttpResultData : JSONModel
@property NSString<Optional>*code;
@property NSString<Optional>*msg;
@property NSMutableArray *data;
@end
@implementation CustomerServiceHttpResultData
@synthesize description;
@end

@interface CustomerServiceHttpResult()
@property CustomerServiceHttpResultData *data;
@end
@implementation CustomerServicePowerHttpPostCmd (Response)
- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    CustomerServiceHttpResult *result = [[CustomerServiceHttpResult alloc]init];
    result = (CustomerServiceHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[CustomerServiceHttpResultData alloc]initWithDictionary:dic error:(NSError **)&error];
        if(error){
            [self onRequestFailed:error];
            return;
        }
    }else{
        NSString *memo = [dic objectForKey:@"error_description"];
        [self.result setResultState:kRequestResultFail];
        [self.result setErrMsg:memo];
        NSLog(@"code :%ld errormsg:%@",(long)code,memo);
    }
}
- (void)onRequestFailed:(NSError *)error{
    NSLog(@"Error===%@",error);
    [self.result setErrMsg:[error localizedDescription]];
    [self.result setResultState:kRequestResultFail];
}
@end
@implementation CustomerServiceHttpResult
- (NSMutableArray *)getCustomerServiceHttpResult{
    
    NSMutableArray *httpArray = [NSMutableArray array];
    if ([self.data.code isEqualToString:@"200"]) {
        httpArray = [NSMutableArray array];
        NSLog(@"%@",[self.data.data componentsJoinedByString:@","]);
        [AccountInfo sharedInstance].CustomerServicePower = [self.data.data componentsJoinedByString:@","];
    } else {
        [httpArray addObject:self.data.msg];
    }
    return httpArray;
}
@end
