#import <Foundation/Foundation.h>

@class Tune;
@class TuneDatabase;

enum {
  kPlaylistTypeSimple = 0,
  kPlaylistTypeSearch = 1,
  kPlaylistTypePredicate = 2,
};

@interface Playlist : NSObject
{
  TuneDatabase *database;
  NSInteger primaryKey;
  BOOL dirty;
  int type;
  BOOL saved;
  NSString *name;
  int sortOrder;

  NSString *abcSearchText;
  NSString *titleSearchText;
  NSString *keySearchText;
  NSString *meterSearchText;
  NSPredicate* predicate;
}

@property (nonatomic, readonly) NSInteger primaryKey;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *abcSearchText;
@property (nonatomic, retain) NSString *titleSearchText;
@property (nonatomic, retain) NSString *keySearchText;
@property (nonatomic, retain) NSString *meterSearchText;
@property (nonatomic, retain) NSPredicate* predicate;
@property (nonatomic, retain) TuneDatabase *database;
@property (nonatomic, assign) int type;
@property (nonatomic, readonly) BOOL saved;

- (id)initWithName:(NSString *)aName abc:(NSString*)abcText title:(NSString*)titleText key:(NSString*)keyText meter:(NSString*)meterText database:(TuneDatabase*)aDatabase;
- (id)initWithPredicate:(NSPredicate*)aPredicate database:(TuneDatabase *)db;
- (id)initWithPrimaryKey:(NSInteger)pk database:(TuneDatabase *)db;
- (void)insertIntoDatabase:(TuneDatabase *)database;
- (void)deleteFromDatabase;

- (void)addTune:(Tune *)tune;
- (void)removeTune:(Tune *)tune;
- (void)removeTuneAtIndex:(int)index;
- (NSMutableArray *)loadTunes;
- (void)updateName:(NSString *)newName;
- (void)updateSortOrder:(NSArray*)tunes;

- (BOOL)isEditable;
- (BOOL)inDatabase;

+ (void)initPlaylists:(TuneDatabase *)database;
+ (void)finalizeStatements;

@end
