
//
//  VankeProjectSummaryAPI.m
//  vanke
//
//  Created by xiaomi on 15/10/6.
//  Copyright © 2015年 gomore. All rights reserved.
//

#import "VankeProjectSummaryAPI.h"
#import "VankeUtil.h"
#import "VankeUserLoginAPI.h"

#pragma mark VankeProjectSummaryAPI

@implementation VankeProjectSummaryAPI

@synthesize salesDate;
@synthesize passengerDate;
@synthesize trafficDate;

-(void) route:(BeeMessage *)msg {
    if (self.sending)
    {
        if (![self checkToQuery]) {
            return;
        }
    
        [self http_get:@"/project/queryclassificationby"].PARAM(@"salesDateEquals", self.salesDate).PARAM(@"passengerDateEquals", self.passengerDate).PARAM(@"trafficDateEquals", self.trafficDate).TIMEOUT(10);
    }
    else if (self.succeed)
    {
        NSLog(@"response: %@", self.responseString);
        
        self.serverResp = [ProjectSummaryResponse objectFromDictionary: self.responseJSONDictionary];
        if ( nil == self.serverResp )
        {
            self.failed = YES;
            return;
        }
    }
}

-(BOOL) checkToQuery {
    if ([VankeUtil isBlankString:self.salesDate]) {
        [self setClientError: @"销量日期不能为空"];
        return NO;
    }
    
    if ([VankeUtil isBlankString:self.passengerDate]) {
        [self setClientError: @"客流量日期不能为空"];
        return NO;
    }
    
    if ([VankeUtil isBlankString:self.trafficDate]) {
        [self setClientError: @"车流量日期不能为空"];
        return NO;
    }
    
    return YES;
}

@end


#pragma mark ProjectSummary

@implementation ProjectSummary

@synthesize classificationName;
@synthesize passengerFlowVolume;
@synthesize trafficVolume;
@synthesize salesAmount;

@end


#pragma mark ProjectSummaryResponse

@implementation ProjectSummaryResponse

@synthesize data;

CONVERT_PROPERTY_CLASS(data, ProjectSummary)

-(ProjectSummary*) getSummary: (NSString*) classificationName {
    if (nil == self.data) {
        return nil;
    }
    
    for (int i = 0; i < [self.data count]; ++i) {
        ProjectSummary *summary = [self.data objectAtIndex:i];
        if ([summary.classificationName eq: classificationName]) {
            return summary;
        }
    }
    return nil;
}

@end

