//
//  GSAxisPart.h
//  GlyphsCore
//
//  Created by Georg Seifert on 29.09.14.
//  Copyright (c) 2014 schriftgestaltung.de. All rights reserved.
//

#import <GlyphsCore/GSContainerProtocol.h>
#import <GlyphsCore/GSBase.h>

@class GSSaveContext;
@class GSAxis;

typedef NS_ENUM(uint8_t, GSPartSetting) {
	GSPartSettingBottom = 1,
	GSPartSettingNone = 0,
	GSPartSettingTop = 2,
};

/**
 The class implementing the properties in Smart Glyphs.

 See also: [GSGlyph.partsSettings]([GSGlyph partsSettings])
 */
@interface GSAxisPart : NSObject

/// @name initialization

/** Initialize the object with a dictionary

 @param dict The content of the dict as it is saved to the .glyphs file

 The dict may look like this:

	{
		bottomValue = 40;
		name = Width;
		topValue = 100;
	}

 @return a new instance

 @see propertyList
 */
- (instancetype)initWithDict:(NSDictionary *)dict;

- (instancetype)initWithName:(NSString *)name bottom:(int)bottom top:(int)top;

/** The content of the object serialized as a dictionary.

 The dict has a format like this:

	{
		bottomValue = 40;
		name = Width;
		topValue = 100;
	}
 @param format the version
 @return a dict

 @see initWithDict:
 */
- (NSDictionary *)propertyListValueFormat:(GSFormatVersion)format error:(out NSError **)error;

//* @name Values

/// The name of the property
@property (strong, nonatomic) NSString *name;

/** A id to use as key in the piece settings in the components

 this allows to change the name and not loose the settings
 */
@property (strong, nonatomic) NSString *axisId;

/// The lower value for the interpolation range
@property (assign, nonatomic) NSInteger bottomValue;

/// The upper value for the interpolation range
@property (assign, nonatomic) NSInteger topValue;
@property (assign, nonatomic) CGFloat pieceValue;

- (CGFloat)valueForPartSetting:(NSNumber *)part;

@property (weak, nonatomic) GSContainer *pieceComponent;

#ifndef GLYPHS_VIEWER
- (BOOL)saveToFile:(FILE *)file format:(GSFormatVersion)formatVersion context:(GSSaveContext *)context error:(NSError **)error;
#endif

+ (GSAxis *)axisFromPartPropertyDict:(NSDictionary *)dict;

@end
