//
//  GSFilterHandler.h
//  GlyphsCore
//
//  Created by Georg Seifert on 28.08.23.
//  Copyright © 2023 schriftgestaltung.de. All rights reserved.
//

#import <GlyphsCore/GlyphsFilterCoreProtocol.h>

NS_ASSUME_NONNULL_BEGIN

extern NSString *GSFilterFilterName;
extern NSString *GSPreFilterFilterName;

#ifndef GLYPHS_VIEWER
extern NSString *GSFilterCallbackName;
extern NSString *GSPreFilterCallbackName;
extern NSString *GSPrepareLayerCallbackName;
extern NSString *GSFontDidOpenCallbackName;
extern NSString *GSFontDidScaleCallbackName;
#endif

@class GSFont;
@class GSLayer;

#ifndef GLYPHS_LITE
NSSet *_Nullable getIncludeExcludeGlyphListFilter(NSArray *arguments, BOOL *include, GSFont *font, NSError **error);
#endif

@interface GSFilterHandler : NSObject

+ (BOOL)applyFilter:(nullable NSArray *)customParameters
			withKey:(NSString *)filterKey
			  error:(NSError **)error
			   font:(GSFont *)font
			  match:(nullable BOOL (^)(NSSet *glyphNames, BOOL include))match
		   callback:(BOOL (^)(id filterInstance, NSArray *arguments))callback;

+ (BOOL)applyLayerCallbacks:(NSArray *)layerCallback toLayer:(GSLayer *)layer error:(out NSError **)error;

// MARK: Callbacks

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

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

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

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

// MARK: Filters

@property (class, nonatomic, readonly) NSArray <GlyphsFilterCore> *filterInstances;

+ (void)addFilterClass:(Class<GlyphsFilterCore>)filterClass;

// MARK: Feature Code Generators

+ (void)addFeatureCodeGenerator:(Class)featureCodeGenerator;

+ (nullable NSArray *)featureCodeGenerators;

// MARK: Exception handling

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

@end

NS_ASSUME_NONNULL_END
