//
//  GSPaletteInfo.h
//  GlyphsCore
//
//  Created by Georg Seifert on 27.09.22.
//  Copyright © 2022 schriftgestaltung.de. All rights reserved.
//

#import <GlyphsCore/GSContainerProtocol.h>

NS_ASSUME_NONNULL_BEGIN

/**
 Key for accessing palettes in the palette.
 */
extern NSString *const GSPalettesPalettesKey;

/**
 Key for accessing color names in the palette.
 */
extern NSString *const GSPalettesColorNamesKey;

/**
 Key for accessing the name of the palette.
 */
extern NSString *const GSPalettesNameKey;

/**
 Key for accessing attributes of the palette.
 */
extern NSString *const GSPalettesAttributesKey;

/**
 Key for accessing colors of the palette.
 */
extern NSString *const GSPalettesColorsKey;

/// Enumeration defining palette attributes.
typedef NS_OPTIONS(NSUInteger, GSPalettesAttribute) {
	/// Usable with light background.
	GSPalettesAttributeLightBackground = 1 << 0,
	/// Usable with dark background.
	GSPalettesAttributeDarkBackground = 1 << 1,
} NS_SWIFT_NAME(GSPalettes.Attribute);

/// This class defines the palettes object which conforms to the GSItemProtocol and NSCopying.
@interface GSPalettes : NSObject <GSItemProtocol, NSCopying>

@property (strong) NSMutableDictionary<NSNumber *, NSString *> *colorNames;
@property (strong) NSMutableArray<NSMutableDictionary *> *palettes;

/// The number of palettes.
@property (readonly) NSUInteger countOfPalettes;

/// The number of colors.
@property (readonly) NSUInteger countOfColors;

/// Returns the same structure as `-propertyListValueFormat:` with the current format, but colors are represented as `GSPaletteColor` objects.
- (id)transferableRepresentation;

/**
 Returns the color for the specified palette and color indices.

 @param paletteIdx The index of the palette.
 @param colorIdx The index of the color.
 @return The color for the specified indices, or nil if not found.
 */
- (nullable NSColor *)colorForPalette:(NSUInteger)paletteIdx forColor:(NSUInteger)colorIdx;

/**
 Returns the colors for the specified palette index.

 @param paletteIdx The index of the palette.
 @return An array of colors for the specified palette.
 */
- (NSArray<NSColor *> *)colorsForPalette:(NSUInteger)paletteIdx;

/**
 Sets the color for the specified palette and color indices.

 @param color The new color.
 @param paletteIdx The index of the palette.
 @param colorIdx The index of the color.
 */
- (void)setColor:(NSColor *)color forPalette:(NSUInteger)paletteIdx forColor:(NSUInteger)colorIdx;

/**
 Returns the name for the specified color index.

 @param colorIdx The index of the color.
 @return The name of the color, or nil if not found.
 */
- (nullable NSString *)nameForColor:(NSUInteger)colorIdx;

/**
 Sets the name for the specified color index.

 @param name The new name.
 @param colorIdx The index of the color.
 */
- (void)setName:(NSString *)name forColor:(NSUInteger)colorIdx;

/**
 Returns the name for the specified palette index.

 @param paletteIdx The index of the palette.
 @return The name of the palette, or nil if not found.
 */
- (nullable NSString *)nameForPalette:(NSUInteger)paletteIdx;

/**
 Returns the display name for the specified palette index.

 @param paletteIdx The index of the palette.
 @return The display name of the palette.
 */
- (NSString *)displayNameForPalette:(NSUInteger)paletteIdx;

/**
 Sets the name for the specified palette index.

 @param name The new name.
 @param paletteIdx The index of the palette.
 */
- (void)setName:(nullable NSString *)name forPalette:(NSUInteger)paletteIdx;

/**
 Adds an attribute to the specified palette index.

 @param attribute The attribute to add.
 @param paletteIdx The index of the palette.
 */
- (void)addAttribute:(GSPalettesAttribute)attribute toPalette:(NSUInteger)paletteIdx;

/**
 Removes an attribute from the specified palette index.

 @param attribute The attribute to remove.
 @param paletteIdx The index of the palette.
 */
- (void)removeAttribute:(GSPalettesAttribute)attribute fromPalette:(NSUInteger)paletteIdx;

/**
 Checks if the specified palette index has the given attribute.

 @param attribute The attribute to check.
 @param paletteIdx The index of the palette.
 @return YES if the palette has the attribute, NO otherwise.
 */
- (BOOL)hasAttribute:(GSPalettesAttribute)attribute inPalette:(NSUInteger)paletteIdx;

/**
 Adds a color to the palettes.

 @param color The color to add.
 */
- (void)addColor:(nullable NSColor *)color;

/**
 Removes the color at the specified index.

 @param colorIdx The index of the color to remove.
 */
- (void)removeColorAtIndex:(NSUInteger)colorIdx;

/**
 Removes the colors at the specified indexes.

 @param colorIndexes The indexes of the colors to remove.
 */
- (void)removeColorsAtIndexes:(NSIndexSet *)colorIndexes;

/**
 Returns the palette at the specified index.

 @param paletteIdx The index of the palette.
 @return A dictionary representing the palette.
 */
- (NSDictionary *)paletteAtIndex:(NSUInteger)paletteIdx;

/// Returns `NSNotFound` when no palette has the given attribute.
- (NSInteger)indexOfPaletteWithAttribute:(GSPalettesAttribute)attribute;

/**
 Adds a palette to the palettes.

 @param palette The palette to add.
 */
- (void)addPalette:(nullable NSMutableDictionary *)palette;

/**
 Removes the palette at the specified index.

 @param paletteIdx The index of the palette to remove.
 */
- (void)removePaletteAtIndex:(NSUInteger)paletteIdx;

@end

NS_ASSUME_NONNULL_END
