//
//  CommandClassControlView.h
//  kneet
//
//  Created by Jason Lee on 3/16/15.
//  Copyright (c) 2015 ntels. All rights reserved.
//

#import <UIKit/UIKit.h>

#define kfSwitchLabelPadding 20.0f
#define kfCommandClassSwitchLeftPadding     30.0f
#define kfCommandClassSwitchRightPadding    40.0f
#define kfCommandClassLockRightPadding      20.0f

#define kfControlDefaultWidth               120.0f
#define kfControlMaxWidth                   IPHONE_WIDTH - 120.0f
#define kfControlDefaultHeight              32.0f

#import "DeviceModel.h"

@class RACDisposable;

typedef void(^NodeCommandCompletionBlock)(id result);
typedef void(^NodeCommandFailureBlock)(id error);

@interface CommandClassControlView : UIView <SocketServiceDelegate>{
@protected
    BOOL _enable, _isConditionMode, _isConditionTypeMode, _isMandatoryNode;
    DeviceModel *_device;
    NodeModel *_node;
    DeviceModel *_selectHub;
    
}
@property (strong, nonatomic) DeviceModel *selectHub;
@property (strong, nonatomic) DeviceModel *device;
@property (strong, nonatomic) NodeModel *node;
@property (assign, nonatomic) BOOL enable;
@property (assign, nonatomic) BOOL isConditionMode;
@property (assign, nonatomic) BOOL isConditionTypeMode;
@property (assign, nonatomic) BOOL isMandatoryNode;
@property (assign, nonatomic) BOOL isReOrderMode;

+ (CommandClassControlView *)viewForCommandClass:(CmdClsType)cmdClsType;
- (void)requestNodeCommand:(NSDictionary *)parameters requestValue:(NSString *)requestValue completionHandler:(NodeCommandCompletionBlock)completion failureHandler:(NodeCommandFailureBlock)failure;

- (void)requestNodeCommand:(NSString *)requestValue;

- (void)requestNodeCommand:(NSDictionary *)parameters requestValue:(NSDictionary *)requestValue;


- (NSDictionary *)parameterForNodeCommand;
- (NSDictionary *)requestValueForNodeCommand:(NSString *)requestValue;
- (CGSize)sizeForIntrinsic;
- (CGSize)sizeForIntrinsicForItemCount:(NSInteger)count;

- (void)setLayoutUI;
- (void)updateLayout;

- (void)updateThingsViewContoller;
+ (NSString *)cmdclsValueForType:(NSString *)dataTypeCode value:(CGFloat)value;


@end

@class CustomSwitch;
@class CustomButton;

@interface CommandClassSwitchView : CommandClassControlView {

@protected
    BOOL _isON;
    __weak CustomLabel *_lblContentValueMsg;
    NSString *_requestValueForOn, *_requestValueForOff;
    __weak NSLayoutConstraint *_constraintBtnSwitchWidth;
}

@property (assign, nonatomic) BOOL isON;
@property (weak, nonatomic) IBOutlet CustomButton *btnSwitch;
@property (weak, nonatomic) IBOutlet CustomLabel *lblContentValueMsg;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraintBtnSwitchWidth;

- (IBAction)btnSwitchTouched:(id)sender;

@end

@interface CommandClassSwitchMultiLevelView : CommandClassControlView {
    NSTimer *_pressTimer;
@protected
    CGFloat _minValue, _maxValue, _currentValue, _step;
}

@property (weak, nonatomic) IBOutlet CustomButton *btnLabel;
@property (weak, nonatomic) IBOutlet CustomButton *btnPlus;
@property (weak, nonatomic) IBOutlet CustomButton *btnMinus;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraintBtnLabelWidth;

- (IBAction)btnPlusTouchDown:(id)sender;
- (IBAction)btnPlusTouchUp:(id)sender;

- (IBAction)btnMinusTouchDown:(id)sender;
- (IBAction)btnMinusTouchUp:(id)sender;

@end


@interface CommandClassValveView : CommandClassControlView {
@protected
    BOOL _isOpened;
    __weak CustomLabel *_lblContentValueMsg;
    NSString *_requestValueForOpen, *_requestValueForClose;
    __weak NSLayoutConstraint *_constraintBtnWidth;
}

@property (assign, nonatomic) BOOL isOpened;
@property (weak, nonatomic) IBOutlet CustomButton *btnOpen;
@property (weak, nonatomic) IBOutlet CustomLabel *lblContentValueMsg;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraintBtnWidth;

- (IBAction)btnOpenTouched:(id)sender;

@end


#pragma mark - Sensors

@class CustomLabel;

@interface CommandClassSensorBinaryView : CommandClassControlView {
@protected
    __weak CustomLabel *_lblControl;
}

@property (weak, nonatomic) IBOutlet CustomLabel *lblControl;
@end


@interface CommandClassSensorMultiLevelView : CommandClassSensorBinaryView

@end


@interface CommandClassMeterCurrentView : CommandClassControlView
@property (weak, nonatomic) IBOutlet CustomLabel *lblMeter;

@end

@interface CommandClassMeterTotalView : CommandClassMeterCurrentView

@end



