//
//  GSCustomParameter.h
//  GlyphsCore
//
//  Created by Georg Seifert on 30.11.12.
//  Copyright (c) 2012 schriftgestaltung.de. All rights reserved.
//

#import <GlyphsCore/GSColorSpace.h>
#import <GlyphsCore/GSIdentifiableParameter.h>
#import <GlyphsCore/GSContainerProtocol.h>

NS_ASSUME_NONNULL_BEGIN

@class GSInstance;
@class GSFont;

extern NSString *const GSCustomParametersIdentifier;
extern NSString *const GSCustomParametersKey;
extern NSString *const GSCustomParameterIgnoreEmptyLayersKey;
extern NSString *const GSCustomParameterEnforceCompatibilityCheckKey;

extern NSString *const GSCustomParameterDisableMasters;
extern NSString *const GSCustomParameterKeepMasters;

extern NSString *const GSCustomParameterReplaceFeature;
extern NSString *const GSCustomParameterReplaceClass;
extern NSString *const GSCustomParameterReplacePrefix;
extern NSString *const GSCustomParameterAddFeature;
extern NSString *const GSCustomParameterAddClass;
extern NSString *const GSCustomParameterAddPrefix;
extern NSString *const GSCustomParameterRemoveFeatures;
extern NSString *const GSCustomParameterRemoveClasses;
extern NSString *const GSCustomParameterRemovePrefixes;
extern NSString *const GSCustomParameterRenameFeature;

/** Implementation of the Custom Property object.

 It stores a name/value pair
 */
#if !(defined(GLYPHS_LITE) || defined(LIBCORE))
@interface GSCustomParameter : NSObject <GSIdentifiableParameter, GSItemProtocol>
#else
@interface GSCustomParameter : NSObject <GSItemProtocol>
#endif

- (instancetype)initWithName:(NSString *)name value:(id)value;

@property (nonatomic, strong) NSString *name;

@property (nonatomic, strong) id value;

@property (nonatomic, strong) id valueUI;

@property (nonatomic, assign) BOOL active;

@property (nonatomic, readonly) BOOL validated;

#ifndef GLYPHS_VIEWER
/// Replaces single quotes with tick marks and removes all non-ASCII characters.
- (NSString *)saveValue;

#endif
/// - Parameter rgbColorSpace: The color space of the font.
/// It must be an RGB color space even when reading the value of a grayscale color.
/// When `nil`, the default RGB color space based on the format version is used.
/// This is not necessarily the color space of the retuned color; for example, grayscale and CMYK color values use different color spaces.
+ (nullable NSColor *)colorFromValue:(id)value colorSpace:(nullable GSColorSpace *)rgbColorSpace format:(GSFormatVersion)format;
/** If the property stores a color, this returns a NSColor object

 It converts a comma separated list of strings into a color. e. g. 0.25,0.65,0.2 will be green
 @return a NSColor object
 */
@property (nonatomic, strong) NSColor *colorValue;

- (nullable NSColor *)colorValueFormat:(GSFormatVersion)format;

- (void)validateValue;

+ (nullable id)defaultValueForKey:(nonnull NSString *)name object:(nonnull GSFont *)object;

- (void)postRead:(GSFormatVersion)formatVersion;

#ifndef GLYPHS_VIEWER
- (void)validateValueFormat:(GSFormatVersion)formatVersion;

+ (NSArray *)validateNameList:(NSArray *)parameter;

- (nullable id)propertyListValueFormat:(GSFormatVersion)formatVersion error:(out NSError **)error;
#endif

+ (id)propertyListValueForColor:(NSColor *)color format:(GSFormatVersion)formatVersion error:(out NSError **)error;

#ifndef GLYPHS_VIEWER
- (nullable NSString *)displayValue;
#endif

- (id)contentValue;

- (NSString *)stringValue;

- (BOOL)boolValue;

- (float)floatValue;

- (NSInteger)integerValue;

- (int)intValue;

#ifndef GLYPHS_VIEWER
- (CGFloat)localizedValueForScript:(NSString *)script;

- (nullable id)valueAsPropertyListValueFormat:(GSFormatVersion)formatVersion context:(nullable GSSaveContext *)context quotesIfNeeded:(BOOL)quotes error:(out NSError **)error;

+ (nullable id)infoPropertyForKeys:(nonnull NSArray *)keys fromObjects:(nonnull NSArray *)objects;

+ (nullable GSCustomParameter *)customParameterForKeys:(nonnull NSArray *)keys fromObjects:(nonnull NSArray *)objects;

// uses customParameter cache.
+ (nullable id)customValueForKeys:(nonnull NSArray *)keys fromObjects:(nonnull NSArray *)objects;

#ifndef LIBCORE
+ (BOOL)convertParameterToProperties:(NSMutableArray *)parameters object:(GSFont *)object error:(NSError **)error;
#ifndef GLYPHS_LITE
+ (void)makeIdentifiers:(NSArray *)parameters;
#endif
#endif
#endif

- (void)setValueFast:(id)value;

#ifndef GLYPHS_LITE
#ifndef GLYPHS_VIEWER
- (void)setParameterIdentifier:(NSString *)parameterIdentifier;
#endif
#endif

#pragma mark - Deprecated (Glyphs 3 compatibility)

+ (nullable NSColor *)colorFromValue:(id)value GSDeprecated("colorFromValue:colorSpace:format:");

@end

NS_ASSUME_NONNULL_END
