//
//  ItemModel.m
//  kneet
//
//  Created by Jason Lee on 4/1/15.
//  Copyright (c) 2015 ntels. All rights reserved.
//

#import "ItemModel.h"
#import "JDObject.h"

@implementation ItemSubModel

+ (JSONKeyMapper *)keyMapper {
    return [JSONKeyMapper mapperFromUnderscoreCaseToCamelCase];
}


- (NSString *)localStringOfDay:(NSString *)day {
    NSString *lstr = nil;
    if ([day isEqualToString:ksDayOfWeekMON]) {
        lstr = NSLocalizedString(@"월", @"월");
    } else if ([day isEqualToString:ksDayOfWeekTUE]) {
        lstr = NSLocalizedString(@"화", @"화");
    } else if ([day isEqualToString:ksDayOfWeekWED]) {
        lstr = NSLocalizedString(@"수", @"수");
    } else if ([day isEqualToString:ksDayOfWeekTHU]) {
        lstr = NSLocalizedString(@"목", @"목");
    } else if ([day isEqualToString:ksDayOfWeekFRI]) {
        lstr = NSLocalizedString(@"금", @"금");
    } else if ([day isEqualToString:ksDayOfWeekSAT]) {
        lstr = NSLocalizedString(@"토", @"토");
    } else if ([day isEqualToString:ksDayOfWeekSUN]) {
        lstr = NSLocalizedString(@"일", @"일");
    }
    return lstr;
}

- (NSString *)daysOfWeek {

    NSMutableString *days = [[NSMutableString alloc] init];
    if (_cmdclsValue && ![_cmdclsValue isEmptyString]) {
        NSArray *darray = [_cmdclsValue componentsSeparatedByString:@","];

        for (NSString *day in darray) {

            NSString *prefix = [days isEmptyString] ? ksEmptyString : @", ";
            [days appendFormat:@"%@%@", prefix, [self localStringOfDay:day]];
        }
    }
    return days;
}


- (NSString *)cmdclsValueMsg {
//    if (!_cmdclsValueMsg || [_cmdclsValueMsg isEmptyString]) {
        if (_dueDate && ![_dueDate isEmptyString]) {
            _cmdclsValueMsg = _dueDate;
        } else if (_daysOfWeek && ![_daysOfWeek isEmptyString]) {
            _cmdclsValueMsg = _daysOfWeek;
        } else if (_dueTime && ![_dueTime isEmptyString]) {
            _cmdclsValueMsg = _dueTime;
        } else if (_homeModes && ![_homeModes isEmptyString]) {
            _cmdclsValueMsg = _homeModes;
        } else if (_externHeat && ![_externHeat isEmptyString]) {
            _cmdclsValueMsg = _externHeat;
        }
//    }
    return _cmdclsValueMsg;

//    if (_dueDate && ![_dueDate isEmptyString]) {
//        self.cmdclsValueMsg = _dueDate;
//
//    } else if (_daysOfWeek && ![_daysOfWeek isEmptyString]) {
//        self.cmdclsValueMsg = _daysOfWeek;
//
//    } else if (_dueTime && ![_dueTime isEmptyString]) {
//        self.cmdclsValueMsg = _dueTime;
//
//    } else if (_homeModes && ![_homeModes isEmptyString]) {
//        self.cmdclsValueMsg = _homeModes;
//
//    } else if (_externHeat && ![_externHeat isEmptyString]) {
//        self.cmdclsValueMsg = _externHeat;
//
//    }
}

@end

@implementation ItemModel

+ (JSONKeyMapper *)keyMapper {

    return [[JSONKeyMapper alloc] initWithDictionary:@{@"pred_item_sequence": @"predItemSequence",
                                                       @"item_type_code": @"itemTypeCode",
                                                       @"item_sub_type_code": @"itemSubTypeCode",
                                                       @"item_name": @"itemName",
                                                       @"item_sub": @"subItems",
                                                       @"pred_action_sequence": @"predActionSequence",
                                                       @"pred_scene_id": @"predSceneId",
                                                       @"pred_rule_id": @"predRuleId",
                                                       @"cnt" : @"cnt",
                                                       @"total_cnt" : @"totalCnt",
                                                       @"image_file_name": @"imageFileName"}];
}

+ (NSString *)itemSubTypeString:(NSString *)itemSubTypeCode {
    NSString *string = ksEmptyString;

    if ([itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {
        string = @"Choose your things & action";
    } else if ([itemSubTypeCode isEqualToString:ksItemSubTypeCodeMode]) {
        string = @"Choose home mode";
    } else if ([itemSubTypeCode isEqualToString:ksItemSubTypeCodeAppPush]) {
        string = @"Choose your things & action";
    }  else if ([itemSubTypeCode isEqualToString:ksItemSubTypeCodeTimer]) {
        string = @"Choose your things & action";
    }
    return string;
}

- (NSInteger)sumPredDeviceCount {
    return _predDevices.count + [_cnt integerValue];
}

- (NSInteger)sumModesCount {
    return _modes.count + [_cnt integerValue];
}

- (NSInteger)sumPushesCount {
    return _pushes.count + [_cnt integerValue];
}

@end

@implementation ItemListModel

@end
