//
//  ItemModel.h
//  kneet
//
//  Created by Jason Lee on 4/1/15.
//  Copyright (c) 2015 ntels. All rights reserved.
//
#import "JDJSONModel.h"

typedef NS_ENUM(NSInteger, CmdClsType) {
    CmdClsTypeFirmwareVersion = 0,
    CmdClsTypeSwitchBinary,         //1
    CmdClsTypeSwitchMultiLevel,
    CmdClsTypeSwitchColor,
    CmdClsTypeSensorBinary,
    CmdClsTypeSensorMultiLevel,     //5
    CmdClsTypeThermostatMode,
    CmdClsTypeThermostatFanMode,
    CmdClsTypeThermostatSetPoint,   //hold
    CmdClsTypeLock,
    CmdClsTypeMeterCurrent,
    CmdClsTypeMeterTotal,
    CmdClsTypeAVControlPlayback,   //12
    CmdClsTypeHomeMode,
    CmdClsTypeSpeedControl,
    CmdClsTypeMeterCurrentForDAWON, //15
    CmdClsTypeMeterTotalForDAWON,
    CmdClsTypeValve,
    CmdClsTypeBattery,
    CmdClsTypeDeviceStatus,         //19
    CmdClsTypePresence,
    CmdClsTypeSystem,
    CmdClsTypeMeter
};

#define ksItemSubTypeCodeDevice     @"01"
#define ksItemSubTypeCodeMode       @"02"
#define ksItemSubTypeCodeAppPush    @"03"
#define ksItemSubTypeCodeTimer      @"05"
#define ksItemSubTypeCodeGeoFencing @"06"
#define ksItemSubTypeCodeHeat       @"31"
#define ksItemSubTypeCodeDaylight   @"32"

#define ksItemTypeCodeTrigger       @"01"
#define ksItemTypeCodeAction        @"02"
#define ksItemTypeCodeCondition     @"03"

#define ksConditionSubTypeCodeDueDate       @"21"
#define ksConditionSubTypeCodeDaysOfWeek    @"22"
#define ksConditionSubTypeCodeDueTime       @"23"
#define ksConditionSubTypeCodeHomeMode      @"02"
#define ksConditionSubTypeCodeExternHeat    @"31"

#define ksConditionTypeCodeGreatOrEqual     @"05"
#define ksConditionTypeCodeLessOrEqual      @"03"

#define ksCmdClassTypeFirmwareVersion @"FIRMWARE_VERSION"
#define ksCmdClassTypeSwitchBinary @"SWITCH_BINARY"
#define ksCmdClassTypeSwitchMultiLevel @"SWITCH_MULTILEVEL"
#define ksCmdClassTypeSwitchColor @"SWITCH_COLOR"
#define ksCmdClassTypeSensorBinary @"SENSOR_BINARY"
#define ksCmdClassTypeSensorMultiLevel @"SENSOR_MULTILEVEL"
#define ksCmdClassTypeThermostatMode @"THERMOSTAT_MODE"
#define ksCmdClassTypeThermostatFanMode @"THERMOSTAT_FAN_MODE"
#define ksCmdClassTypeThermostatSetPoint @"THERMOSTAT_SETPOINT"
#define ksCmdClassTypeLock @"LOCK"
#define ksCmdClassTypeMeterCurrent @"METER_CURRENT"
#define ksCmdClassTypeMeterTotal @"METER_TOTAL"
#define ksCmdClassTypeAVControlPlayback @"AV_CONTROL_PLAYBACK"
#define ksCmdClassTypeHomeMode @"HOME_MODE"
#define ksCmdClassTypeSpeedControl      @"SPEED_CONTROL"
#define ksCmdClassTypeValve             @"VALVE"
#define ksCmdClassTypeBattery           @"BATTERY"
#define ksCmdClassTypeDeviceStatus      @"DEVICE_STATUS"
#define ksCmdClassTypePresence          @"PRESENCE"
#define ksCmdClassTypeSystem            @"SYSTEM"
#define ksCmdClassTypeMeter             @"METER"


@protocol ItemModel;
@protocol ItemSubModel;
@protocol ModeModel;
@protocol DeviceModel;

@protocol CmdClsValueModel;
@interface CmdClsValueModel : JDJSONModel

@property (copy, nonatomic) NSString *cmdclsValue;
@property (copy, nonatomic) NSString *cmdclsValueMsg;

@property (assign, nonatomic) BOOL isSelected;

//local
@property (strong, nonatomic) NSString *localizedCmdClsValueMsg;

@end

@interface ItemSubModel : JDJSONModel {//subCondition
@protected
    NSString *_cmdclsTypeId;
    NSString *_cmdclsValueMsg;
    NSArray<CmdClsValueModel> *_cmdclsValueList;
    NSString *_unit;
}

//@property (copy, nonatomic) NSString *itemSubTypeCode;
@property (copy, nonatomic) NSString *subSequence;
@property (copy, nonatomic) NSString *sourceId;
@property (copy, nonatomic) NSString *sourceSubId;
@property (copy, nonatomic) NSString *conditionTypeCode;
@property (copy, nonatomic) NSString *sourceName;
@property (copy, nonatomic) NSString *sourceSubName;
@property (copy, nonatomic) NSString *actionTypeCode;

@property (copy, nonatomic) NSString *cmdclsCode;
@property (assign, nonatomic, readonly) CmdClsType cmdclsType;
@property (copy, nonatomic) NSString *cmdclsTypeId;
@property (copy, nonatomic) NSString *cmdclsTypeName;
@property (copy, nonatomic) NSString *cmdclsTypeSystemName;
@property (copy, nonatomic) NSString *cmdclsValue;
@property (copy, nonatomic) NSString *cmdclsValueMsg;
@property (copy, nonatomic) NSString *onlineState;

//predefine devices property
@property (copy, nonatomic) NSString *controlMinValue;
@property (copy, nonatomic) NSString *controlMaxValue;
@property (copy, nonatomic) NSString *controlStep;
@property (copy, nonatomic) NSString *unit;


@property (copy, nonatomic) NSString *dataTypeCode;
@property (copy, nonatomic) NSString *deleteYn;
@property (copy, nonatomic) NSString *imageFileName;
@property (copy, nonatomic) NSString *imageFileViewName;

@property (copy, nonatomic) NSString *hour;
@property (copy, nonatomic) NSString *minute;
@property (copy, nonatomic) NSString *dayofweek;
@property (copy, nonatomic) NSString *nickname;
@property (copy, nonatomic) NSString *predCmdclsValue;

//Command - things, modes
@property (copy, nonatomic) NSString *status;

@property (strong, nonatomic) NSMutableArray<ItemModel> *conditions;
@property (copy, nonatomic) NSArray<CmdClsValueModel> *cmdclsValueList;

@property (assign, nonatomic, readonly) NSInteger cmdclsValueMsgLength;
@property (strong, nonatomic) NSString<Ignore> *cmdclsValueMsgLongest;


//flash
@property (copy, nonatomic) NSString<Ignore> *dueDate;
//@property (copy, nonatomic) NSString<Ignore> *daysOfWeek;
@property (copy, nonatomic) NSString<Ignore> *dueTime;
@property (copy, nonatomic) NSString<Ignore> *homeModes;
@property (copy, nonatomic) NSString<Ignore> *externHeat;
@property (copy, nonatomic) NSString<Ignore> *daysOfWeekValue;

//- (NSString *)cmdclsValueMsg:(NSString *)cmdclsValue;

//local transition
@property (assign, nonatomic, readonly) BOOL isOnline;

@end

@protocol PredefinedDeviceModel;
@interface ItemModel : JDJSONModel  //condition

@property (copy, nonatomic) NSString *predItemSequence;
@property (copy, nonatomic) NSString *itemTypeCode;
@property (copy, nonatomic) NSString *itemSubTypeCode;
@property (copy, nonatomic) NSString *itemName;

@property (copy, nonatomic) NSString *predRuleId;

@property (copy, nonatomic) NSString *predSceneId;
@property (copy, nonatomic) NSString *predActionSequence;
@property (copy, nonatomic) NSString *cnt;
@property (copy, nonatomic) NSString *totalCnt;
@property (copy, nonatomic) NSString *imageFileName;

@property (copy, nonatomic) NSString *sourceId;
@property (copy, nonatomic) NSString *sourceName;
@property (copy, nonatomic) NSString *imageFileViewName;


@property (strong, nonatomic) NSMutableArray<ItemSubModel> *subItems;

//for register
@property (strong, nonatomic) NSMutableArray<PredefinedDeviceModel> *predDevices;
@property (strong, nonatomic) NSMutableArray<ModeModel> *modes;
@property (strong, nonatomic) NSMutableArray<ItemSubModel> *pushes;
@property (strong, nonatomic) NSMutableArray<ItemSubModel> *timers;
@property (strong, nonatomic) NSMutableArray<ItemSubModel> *daylights;
@property (strong, nonatomic) NSMutableArray<ItemSubModel> *heats;
@property (strong, nonatomic) NSMutableArray<DeviceModel> *mobileDevices;

//fuction
@property (assign, nonatomic, readonly) NSInteger sumPredDeviceCount;
@property (assign, nonatomic, readonly) NSInteger sumModesCount;
@property (assign, nonatomic, readonly) NSInteger sumPushesCount;

+ (NSString *)itemSubTypeString:(NSString *)itemSubTypeCode;

@end

@interface ItemListModel : JDJSONModel
@property (copy, nonatomic) NSMutableArray<ItemModel> *list;
@end

@interface ItemSubListModel : JDJSONModel
@property (copy, nonatomic) NSMutableArray<ItemSubModel> *list;
@end
