//
//  MessageTemplateHttpPostCmd+Response.m
//  MobilePortal
//
//  Created by caiyang on 2020/5/12.
//  Copyright © 2020 yin chen. All rights reserved.
//

#import "MessageTemplateHttpPostCmd+Response.h"
#import "MessageTemplateHttpPostCmd.h"
#import "MessageTemplateHttpResult.h"

@protocol MessageTemplateHttpResultDataDataList;
@interface MessageTemplateHttpResultDataDataList : JSONModel
@property NSString<Optional>*id;
@property NSString<Optional>*title;
@property NSString<Optional>*messagetype;
@property NSString<Optional>*priority;
@property NSString<Optional>*limitation;
@property NSString<Optional>*starttime;
@property NSString<Optional>*endtime;
@property NSString<Optional>*remarks;
@property NSString<Optional>*content;
@property NSString<Optional>*createby;
@property NSString<Optional>*createon;
@property NSString<Optional>*updateby;
@property NSString<Optional>*updateon;
@property NSString<Optional>*companyname;
@end
@implementation MessageTemplateHttpResultDataDataList
@synthesize description;
@end

@protocol MessageTemplateHttpResultDataData;
@interface MessageTemplateHttpResultDataData : JSONModel
@property NSMutableArray<Optional,MessageTemplateHttpResultDataDataList> *list;
@end
@implementation MessageTemplateHttpResultDataData
@synthesize description;
@end

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

@interface MessageTemplateHttpResult()
@property MessageTemplateHttpResultData *data;
@end

@implementation MessageTemplateHttpPostCmd (Response)

- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    MessageTemplateHttpResult *result = [[MessageTemplateHttpResult alloc]init];
    result = (MessageTemplateHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[MessageTemplateHttpResultData 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 MessageTemplateHttpResult
- (NSMutableArray *)getMessageTemplateHttpResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    for (int index = 0 ; index < self.data.data.list.count; index ++) {
        MessageTemplateHttpResultDataDataList *httpModel = self.data.data.list[index];
        MessageTemplateModel *model = [[MessageTemplateModel  alloc]init];
        model.id = [self getNilString:httpModel.id];
        model.title = [self getNilString:httpModel.title];
        model.messagetype = [self getNilString:httpModel.messagetype];
        model.priority = [self getNilString:httpModel.priority];
        model.limitation = [self getNilString:httpModel.limitation];
        model.starttime = [self getNilString:httpModel.starttime];
        model.endtime = [self getNilString:httpModel.endtime];
        model.remarks = [self getNilString:httpModel.remarks];
        model.content = [self getNilString:httpModel.content];
        model.createby = [self getNilString:httpModel.createby];
        model.createon = [self getNilString:httpModel.createon];
        model.updateby = [self getNilString:httpModel.updateby];
        model.updateon = [self getNilString:httpModel.updateon];
        model.companyname = [self getNilString:httpModel.companyname];
        [httpArray addObject:model];
    }
    
    return httpArray;
}
@end
