//
//  GSCallbackHandler.h
//  GlyphsCore
//
//  Created by Georg Seifert on 08/10/2016.
//  Copyright © 2016 schriftgestaltung.de. All rights reserved.
//

NS_ASSUME_NONNULL_BEGIN

extern NSString *GSDrawForegroundCallbackName;
extern NSString *GSDrawBackgroundCallbackName;
extern NSString *GSDrawInactiveCallbackName;
extern NSString *GSDrawFontViewCallbackName;
extern NSString *GSDrawPreviewCallbackName;

extern NSString *GSInspectorViewControllersCallbackName;
extern NSString *GSPanelInspectorsViewControllersCallbackName;
extern NSString *GSContextMenuCallbackName;
extern NSString *GSSelectionChangeCallbackName;
extern NSString *GSFilterFlatKerning;
extern NSString *GSHandleCustomFiles;
extern NSString *GSVisibleReportersKey;
extern NSString *GSShowUnicodeInfoCallbackName;

@protocol GlyphsReporter;
@protocol GSFontCheckerProtocol;
@protocol GlyphsCallback;

@class MGOrderedDictionary;
@class GSFont;
@class GSLayer;
@class GSGlyph;

@protocol ShowUnicodeInfoProtocol <NSObject>
/// return YES you handled the request, otherwise, NO;
- (BOOL)showUnicodeInfo:(GSGlyph *)glyph;

@end


void setCrashContext(NSString * _Nullable crashContext);
NSString * _Nullable getCrashContext(void);

@protocol GSFilterFlatKerningProtocol <NSObject>

// return the new kerning list or nil if there was a problem (set a meaningful error)
- (NSArray *)filterFlatKerning:(NSArray *)flatKerning font:(GSFont *)font error:(out NSError **)error;

@end

@interface GSCallbackHandler : NSObject

@property (class, nonatomic, strong) MGOrderedDictionary *reporterInstances;

- (instancetype)init __attribute__((unavailable("use class methods")));

+ (BOOL)validateVersions:(NSDictionary *)currDict;

/// All currently active reporter instances.
+ (NSArray<NSObject<GlyphsReporter> *> *)activeReporters NS_SWIFT_UI_ACTOR;
/// All currently active reporter instances mapped from their class name.
+ (NSDictionary<NSString *, NSObject<GlyphsReporter> *> *)activeReportersMap NS_SWIFT_UI_ACTOR;

/// disables all active reporters
+ (void)resetActiveReporters;

/// toggles the reporter
+ (void)toggleActiveReporter:(NSObject<GlyphsReporter> *)reporter;

/// activates the reporter
+ (void)activateReporter:(NSObject<GlyphsReporter> *)reporter;

/// deactivates the reporter
+ (void)deactivateReporter:(NSObject<GlyphsReporter> *)reporter;

/// deactivates the reporters
+ (void)deactivateReporters:(NSArray<NSObject<GlyphsReporter> *> *)reporters;

// MARK: Callbacks

/// all active callbacks
+ (NSDictionary <NSString *, NSArray *> *)activeCallbacks;

/// the callbacks for a certain callbackType
+ (nullable NSArray *)callbacksForType:(NSString *)callbackType;

+ (void)addCallback:(id)target forOperation:(NSString *)operation;

+ (void)removeCallback:(id)target forOperation:(NSString *)operation;

#ifndef LIBCORE
+ (void)registerFontChecker:(NSObject<GSFontCheckerProtocol> *)checker;

+ (NSArray *)fontCheckers;
#endif
#ifndef GLYPHS_LITE
+ (void)respondToReporterCrash:(NSObject<GlyphsReporter> *)reporter exception:(NSException *)exception;

+ (void)respondToException:(NSException *)exception;

/// add class of view controller that handles UI for parameterName
+ (void)addCustomParameterViewClass:(Class)parameterClass forParameter:(NSString *)parameterName;

/// add class of window controller that handles UI for parameterName
+ (void)addCustomParameterSheetController:(Class)propertyDialogClass forParameter:(NSString *)parameterName;

#if !LIBCORE && !TARGET_OS_IOS
+ (void)addEditViewLeftSidebarController:(Class)sidebarController;

+ (NSArray <Class> *)editViewLeftSidebarControllers;
#endif
#endif

@end

NS_ASSUME_NONNULL_END
