//
//  MessageNunberShowHttpPostCmd+Response.m
//  MobilePortal
//
//  Created by caiyang on 2020/6/4.
//  Copyright © 2020 yin chen. All rights reserved.
//
#import "MessageNunberShowHttpPostCmd.h"
#import "MessageNumberShowHttpResult.h"
#import "MessageNunberShowHttpPostCmd+Response.h"


@protocol MessageNumberShowHttpResultData;
@interface MessageNumberShowHttpResultData : JSONModel
@property NSString<Optional>*total;
@property NSString<Optional>*pages;
@property NSString<Optional>*pageNum;
@property NSString<Optional>*pageSize;
@end
@implementation MessageNumberShowHttpResultData
@synthesize description;
@end

@interface MessageNumberShowHttpResult()
@property MessageNumberShowHttpResultData *data;
@end


@implementation MessageNunberShowHttpPostCmd (Response)

- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    MessageNumberShowHttpResult *result = [[MessageNumberShowHttpResult alloc]init];
    result = (MessageNumberShowHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[MessageNumberShowHttpResultData 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 MessageNumberShowHttpResult
- (NSMutableArray *)getMessageNumberShowHttpResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    MessageNumberShowModel *model = [[MessageNumberShowModel alloc]init];
    model.total = [self getNilString:self.data.total];
    int intString = [model.total intValue];
    if (intString > 99) {
        model.total = @"99+";
    }
    model.pages = [self getNilString:self.data.pages];
    model.pageNum = [self getNilString:self.data.pageNum];
    model.pageSize = [self getNilString:self.data.pageSize];
    [httpArray addObject:model];
    return httpArray;
}
@end
