//
//  GSShortCutItem.h
//  ShortCutPreferences
//
//  Created by Georg Seifert on 07.01.19.
//  Copyright © 2019 Georg Seifert. All rights reserved.
//

NS_ASSUME_NONNULL_BEGIN

@protocol GSShortcutCommandProtocol;

typedef enum : NSUInteger {
	GSCommandTypeMainMenu,
	GSCommandTypeCustom,
	GSCommandTypeTool,
} GSCommandType;

@interface GSShortcutItem : NSObject <NSCopying>

@property (nonatomic, strong) NSString *group;
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSArray<NSString *> *qualifiedName;
/// Short string describing the shortcut. `nil` if the item has no shortcut.
@property (nonatomic, readonly, nullable) NSString *shortcutId;
@property (nonatomic, strong, nullable) NSString *identifier;
@property (nonatomic) GSCommandType type;
@property (nonatomic) SEL action;
@property (nonatomic, weak) id target;

@property (nonatomic) uint16_t keyCode;
@property (nonatomic) NSEventModifierFlags modifierFlags;

@property (nonatomic, readonly) uint16_t defaultKeyCode;
@property (nonatomic, readonly) NSEventModifierFlags defaultModifierFlags;

@property (nonatomic, readonly) BOOL isDefault;
/// Inverse of `isDefault` for bindings (`NSNegativeBoolean` would mess with `NSDictionary` items)
@property (nonatomic, readonly) BOOL isCustomized;
@property (strong) NSArray *conflictingCommands;
@property (nonatomic, readonly) BOOL isConflicting;
@property (weak) NSMenuItem *menuItem;

@property (nonatomic, strong, nullable) NSString *userDefaultsKey;

- (instancetype)initWithTitle:(NSString *)title group:(nullable NSString *)group identifier:(nullable NSString *)identifier action:(SEL)action target:(nullable NSObject<GSShortcutCommandProtocol> *)target character:(nullable NSString *)character modifierFlags:(NSEventModifierFlags)modifierFlags menuItem:(nullable NSMenuItem *)menuItem userKeyEquivalents:(nullable NSDictionary<NSString *, NSString *> *)userKeyEquivalents;

- (instancetype)initWithTitle:(NSString *)title group:(NSString *)group identifier:(NSString *)identifier key:(NSString *)userDefaultsKey;

- (void)setKeyCodeFromCharacter:(CFStringRef)character;
- (void)configureWithMenuItem:(NSMenuItem *)menuItem userKeyEquivalents:(nullable NSDictionary<NSString *, NSString *> *)userKeyEquivalents;
- (void)loadSettings;
- (void)storeInSettings;
- (void)removeFromSettings;
@end

NS_ASSUME_NONNULL_END
