//
//  DetailsHttpGetCmd+Response.m
//  MobilePortal
//
//  Created by caiyang on 2020/4/8.
//  Copyright © 2020 yin chen. All rights reserved.
//

#import "DetailsHttpGetCmd+Response.h"
#import "DetailsHttpGetResult.h"

@protocol DetailsHttpGetResultData;
@interface DetailsHttpGetResultData : JSONModel
@property NSString<Optional>*id;
@property NSString<Optional>*folderid;
@property NSString<Optional>*title;
@property NSString<Optional>*status;
@property NSString<Optional>*createon;
@property NSString<Optional>*createby;
@property NSString<Optional>*orderType;
@property NSString<Optional>*createbyname;
@property NSString<Optional>*docname;
@property NSString<Optional>*type;
@property NSString<Optional>*foldertype;
@property NSString<Optional>*content;
@end
@implementation DetailsHttpGetResultData
@synthesize description;
@end


@interface DetailsHttpGetResult()
@property DetailsHttpGetResultData *data;
@end


@implementation DetailsHttpGetCmd (Response)

- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    DetailsHttpGetResult *result = [[DetailsHttpGetResult alloc]init];
    result = (DetailsHttpGetResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[DetailsHttpGetResultData 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 DetailsHttpGetResult
- (NSMutableArray *)getDetailsHttpGetResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    DetailsHttpModel *model = [[DetailsHttpModel alloc]init];
    model.id = [self getNilString:self.data.id];
    model.content = [self getNilString:self.data.content];
//    model.content = @"";
    model.folderid = [self getNilString:self.data.folderid];
    model.title = [self getNilString:self.data.title];
    model.status = [self getNilString:self.data.status];
    model.createon = [self getNilString:self.data.createon];
    model.createby = [self getNilString:self.data.createby];
    model.createbyname = [self getNilString:self.data.createbyname];
    model.docname = [self getNilString:self.data.docname];
    model.type = [self getNilString:self.data.type];
    model.foldertype = [self getNilString:self.data.foldertype];
    [httpArray addObject:model];
    return httpArray;
}
@end
