//
//  QueryParamsTools.m
//  ALand
//
//  Created by Z on 16/7/22.
//  Copyright © 2016年 Z. All rights reserved.
//

#import "QueryParamsTools.h"

@interface QueryParamsTools ()
@property (nonatomic, strong) NSMutableDictionary *defintion;
@property (nonatomic, strong) NSMutableArray *arrFetchParts;
@property (nonatomic, strong) NSMutableArray *orders;
@property (nonatomic, strong) NSMutableArray *conditions;


@end
@implementation QueryParamsTools
+ (QueryParamsTools *)queryParamsToolWithPage:(NSNumber *)page pageSize:(NSNumber *)pageSize {
    QueryParamsTools *tools = [[self alloc] initWithWithPage:page pageSize:pageSize];
    return tools;
}

- (instancetype)initWithWithPage:(NSNumber *)page pageSize:(NSNumber *)pageSize {
    self = [super init];
    if (self) {
        self.params = [NSMutableDictionary dictionary];
        self.defintion = [NSMutableDictionary dictionary];
        self.arrFetchParts = [NSMutableArray array];
        self.orders = [NSMutableArray array];
        self.conditions = [NSMutableArray array];
        
        [self.defintion setValue:page forKey:@"page"];
        [self.defintion setValue:pageSize forKey:@"pageSize"];
        [self.defintion setValue:@0 forKey:@"probePages"];
        [self.defintion setObject:self.conditions forKey:@"conditions"];
        [self.defintion setObject:self.orders forKey:@"orders"];
        [self.params setObject:self.defintion forKey:@"defintion"];
    }
    return self;
}

- (void)addOrderField:(NSString *)order direction:(NSString *)direction {
    NSDictionary *myDictionary = @{@"field" : order,
                                   @"direction" : direction};
    [self.orders addObject:myDictionary];
}
- (void)addConditionsOperation:(NSString *)condition value:(NSString *)value {
    NSDictionary *myDictionary = @{@"operation" : condition,
                                   @"parameters" : @[value]};
    [self.conditions addObject:myDictionary];
}
@end
