//
//  GSDrawEnvironment.h
//  GlyphsCore
//
//  Created by Florian Pircher on 2025-07-21.
//  Copyright © 2025 schriftgestaltung.de. All rights reserved.
//



@class GSFont;
@class GSFontMaster;
@class GSLayer;
@class GSInstance;
#ifndef GLYPHS_LITE
@class GSPalettes;
#endif
NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(uint8_t, GSDrawEnvironmentSetting) {
	GSDrawEnvironmentSettingPrimary,
	GSDrawEnvironmentSettingLightBackground,
	GSDrawEnvironmentSettingDarkBackground,
} NS_SWIFT_NAME(GSDrawEnvironment.Setting);

GSDrawEnvironmentSetting GSDrawEnvironmentCurrentDrawingSetting(void) NS_SWIFT_NAME(GSDrawEnvironmentSetting.current());

@interface GSDrawEnvironment : NSObject

@property (strong, nullable, nonatomic) NSColor *foregroundColor;
#ifndef GLYPHS_LITE
@property (strong, nullable, direct) GSPalettes *colorPalettes;
#endif
@property (assign, direct) GSDrawEnvironmentSetting setting;
/// The scale factor of the rendered dimensions in relation to the source dimensions.
///
/// For example, drawing a 1000 by 1000 font unit layer to a 500 by 500 point bitmap context yields a scale of 0.5.
@property (assign, direct) CGFloat scale;
/// The render unit length.
///
/// For example, a 2x display uses a pixel length of 2.
/// A 200 by 200 point bitmap context then produces a 400 by 400 pixel image.
@property (assign, direct) CGFloat factor;
/// A context layer for looking up additional details.
///
/// `nil` when no single layer context exists.
@property (strong, nullable, nonatomic) GSLayer *layer;
/// A context master for looking up additional details.
///
/// `nil` when no single master context exists.
///
/// Setting the layer also sets this property.
@property (strong, nullable, nonatomic) GSFontMaster *master;
/// A context font for looking up additional details.
///
/// `nil` when no single font context exists.
///
/// Setting the master also sets this property.
@property (strong, nullable, nonatomic) GSFont *font;
/// A context instance for looking up additional details.
///
/// `nil` when no single instance context exists.
@property (strong, nullable, direct) GSInstance *instance;

#ifndef GLYPHS_LITE
/// The container can be a font or font master.
///
/// For a layer, the associated master should be used as the representative palette container:
///
/// ```
/// container = [layer.font fontMasterForId:layer.associatedMasterId];
/// ```
- (void)updateColorPalettesWithContainer:(nullable id)container;
#endif

/// Returns `nil` when the argument is `nil`; `GSPaletteColor.errorColor` when the given palette color cannot be resolved.
- (nullable NSColor *)resolveColor:(nullable NSColor *)color;

- (CGFloat)resolveExpression:(nullable id)expression withDefault:(CGFloat)defaultValue;
- (CGFloat)resolveExpression:(id)expression;

@end

NS_ASSUME_NONNULL_END
