//
//  WeChatTypeHttpPostCmd+Response.m
//  MobilePortal
//
//  Created by caiyang on 2020/9/21.
//  Copyright © 2020 yin chen. All rights reserved.
//

#import "WeChatTypeHttpPostCmd+Response.h"
#import "WeChatTypeHttpPostCmd.h"
#import "WeChatTypeHttpResult.h"


@protocol WeChatTypeHttpResultDataItem;
@interface WeChatTypeHttpResultDataItem : JSONModel
@property NSString<Optional>*id;
@property NSString<Optional>*name;
@property NSString<Optional>*system;
@property NSString<Optional>*sort;
@property NSString<Optional>*keyword;
@property NSString<Optional>*content;
@property NSString<Optional>*companyname;
@property NSString<Optional>*createon;
@property NSString<Optional>*updateon;
@property NSString<Optional>*state;
@end
@implementation WeChatTypeHttpResultDataItem
@synthesize description;
@end


@protocol WeChatTypeHttpResultDataData;
@interface WeChatTypeHttpResultDataData : JSONModel
@property NSString<Optional>*pageNum;
@property NSString<Optional>*pageSize;
@property NSMutableArray<WeChatTypeHttpResultDataItem, Optional>*list;
@end
@implementation WeChatTypeHttpResultDataData
@synthesize description;
@end



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

@interface WeChatTypeHttpResult()
@property WeChatTypeHttpResultData *data;
@end

@implementation WeChatTypeHttpPostCmd (Response)

- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    WeChatTypeHttpResult *result = [[WeChatTypeHttpResult alloc]init];
    result = (WeChatTypeHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[WeChatTypeHttpResultData 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 WeChatTypeHttpResult
- (NSMutableArray *)getWeChatTypeHttpResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    for (int index = 0 ; index < self.data.data.list.count; index ++) {
        WeChatTypeHttpResultDataItem *httpModel = self.data.data.list[index];
        ScopeListHttpModel *model = [[ScopeListHttpModel alloc]init];
        model.system = [self getNilString:httpModel.system];
        model.content = [self getNilString:httpModel.content];
        model.sort = [self getNilString:httpModel.sort];
        model.id = [self getNilString:httpModel.id];
        model.updateon = [self getNilString:httpModel.updateon];
        model.keyword = [self getNilString:httpModel.keyword];
        model.name = [self getNilString:httpModel.name];
        model.createon = [self getNilString:httpModel.createon];
        model.state = [self getNilString:httpModel.state];
        [httpArray addObject:model];
    }
    return httpArray;
}
@end
