//
//  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               134.0f
#define kfControlMaxWidth                   IPHONE_WIDTH - 120.0f
#define kfControlDefaultHeight              32.0f

#import "DeviceModel.h"

typedef void(^NodeCommandCompletionBlock)(id result);
typedef void(^NodeCommandFailureBlock)(id error);
@interface CommandClassControlView : UIView {

@protected
    NSString *_requestValueForOn, *_requestValueForOff;
    BOOL _enable, _isConditionMode, _isConditionTypeMode;
    DeviceModel *_device;
    NodeModel *_node;
}
@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;

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

- (NSDictionary *)parameterForNodeCommand;
- (CGSize)sizeForIntrinsic;
- (CGSize)sizeForIntrinsicForItemCount:(NSInteger)count;
- (void)updateThingsViewContoller;

@end

@class CustomSwitch;
@class CustomButton;

@interface CommandClassSwitchView : CommandClassControlView {

@protected
    NSString *_sOn, *_sOff;
}

@property (assign, nonatomic) BOOL isON;
@property (weak, nonatomic) IBOutlet CustomButton *btnSwitch;
@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 CommandClassThermostatModeView : CommandClassControlView {
    NSArray *_modeArray;
    NSInteger _modeIndex;
    NSTimer *_pressTimer;
}

@property (weak, nonatomic) IBOutlet CustomButton *btnLabel;
@property (weak, nonatomic) IBOutlet CustomButton *btnNext;
@property (weak, nonatomic) IBOutlet CustomButton *btnPrev;

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

- (IBAction)btnNextTouchDown:(id)sender;
- (IBAction)btnNextTouchUp:(id)sender;

- (IBAction)btnPrevTouchDown:(id)sender;
- (IBAction)btnPrevTouchUp:(id)sender;

@end

@interface CommandClassThermostatFanModeView : CommandClassThermostatModeView

@end


@interface CommandClassThermostatSetPointView : CommandClassControlView {

@protected
    CGFloat _minValue, _maxValue, _currentValue, _step;
    NSTimer *_pressTimer;
}

@property (weak, nonatomic) IBOutlet CustomButton *btnLabel;
@property (weak, nonatomic) IBOutlet CustomButton *btnUp;
@property (weak, nonatomic) IBOutlet CustomButton *btnDown;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraintBtnLabelWidth;
- (IBAction)btnUpTouchDown:(id)sender;
- (IBAction)btnUpTouchUp:(id)sender;

- (IBAction)btnDownTouchDown:(id)sender;
- (IBAction)btnDownTouchUp:(id)sender;

@end


@interface CommandClassLockView : CommandClassSwitchView {
@protected
    NSString *_sLocked, *_sUnlocked;
}

@property (assign, nonatomic) BOOL isLocked;

@property (weak, nonatomic) IBOutlet CustomButton *btnLabel;
@property (weak, nonatomic) IBOutlet CustomButton *btnLock;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraintBtnLabelWidth;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraintBtnLockWidth;

- (IBAction)btnLockTouched:(id)sender;

@end


@interface CommandClassAVPlaybackView : CommandClassControlView

@property (assign, nonatomic) BOOL isPlay;
@property (weak, nonatomic) IBOutlet CustomButton *btnPlayback;
- (IBAction)btnPlaybackTouched:(id)sender;

@end

#pragma mark - Sensors

@class CustomLabel;

@interface CommandClassSensorBinaryView : CommandClassControlView

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


@interface CommandClassSensorMultiLevelView : CommandClassSensorBinaryView

@end


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

@end

@interface CommandClassMeterTotalView : CommandClassMeterCurrentView

@end

@interface CommandClassCameraStreamView : CommandClassControlView

@property (weak, nonatomic) IBOutlet CustomLabel *lblCamera;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraintControlLabelWidth;

@end

@interface CommandClassSpeedControlView : CommandClassControlView {
    NSArray *_modeArray;
    NSInteger _modeIndex;
    NSTimer *_pressTimer;
}

@property (weak, nonatomic) IBOutlet CustomButton *btnLabel;
@property (weak, nonatomic) IBOutlet CustomButton *btnNext;
@property (weak, nonatomic) IBOutlet CustomButton *btnPrev;

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

- (IBAction)btnNextTouchDown:(id)sender;
- (IBAction)btnNextTouchUp:(id)sender;

- (IBAction)btnPrevTouchDown:(id)sender;
- (IBAction)btnPrevTouchUp:(id)sender;

@end


