//
//  table_C_P_A_L_.h
//  GSFontTools
//
//  Created by Georg Seifert on 31.07.13.
//
//

#import <GSFontTools/TTTable.h>

typedef NS_ENUM(uint8, OTPaletteType) {
	OTPaletteTypeDefault = 0,
	OTPaletteTypeLight = 1 << 0,
	OTPaletteTypeDark = 1 << 1,
};

#define OTPaletteNoNameID 0xFFFF

@class table__n_a_m_e;

@interface OTColorRecord : NSObject <NSCopying> {
	NSColor *_color;
  @public
	uint8_t _blue;	// Blue value (B0).
	uint8_t _green; // Green value (B1).
	uint8_t _red;	// Red value (B2).
	uint8_t _alpha; // Alpha value (B3).
}
@property (nonatomic, retain) NSColor *color;
- (BOOL)decompile:(NSData *)data pos:(NSUInteger *)pos font:(TTFont *)font error:(NSError **)error;
- (BOOL)compile:(NSMutableData *)data error:(NSError **)error;
- (void)toXML:(GSXMLWriter *)writer index:(NSUInteger)idx;
@end

@interface table_C_P_A_L_ : TTTable {
	uint16_t _version; // Table version number (0).
	// uint16_t       _numPaletteEntries;                 // Number of palette entries in each palette.
	// uint16_t       _numPalettes;                       // Number of palettes in the table.
	// uint16_t       _numColorRecords;                   // Total number of color records, combined for all palettes.
	// uint32_t       _offsetFirstColorRecord;            // Offset from the beginning of CPAL table to the first ColorRecord.
	// NSMutableIndexSet * _colorRecordIndices;           //[numPalettes]   //Index of each palette's first color record in the combined color record array.
	// NSMutableArray *  _colorRecords;                   // Color records for all palettes.
	NSMutableArray *_colorPalettes;
}

/// - Parameter palettes: An array of palettes; a palette is an array of colors; a color is an RGBA-array of NSNumber bytes.
+ (table_C_P_A_L_ *)buildWithPalettes:(NSArray<NSArray<NSArray<NSNumber *> *> *> *)palettes
						 paletteTypes:(NSArray<NSNumber *> *)paletteTypes
						paletteLabels:(NSArray *)paletteLabels
				   paletteEntryLabels:(NSArray *)paletteEntryLabels
							nameTable:(table__n_a_m_e *)nameTable
								error:(NSError **)error;

@property (nonatomic) uint16_t version;
@property (nonatomic, retain) NSArray *colorPalettes;
@property (nonatomic, retain) NSArray *paletteTypes;
@property (nonatomic, retain) NSArray *paletteLabels;
@property (nonatomic, retain) NSArray *paletteEntryLabels;

@end
