#import <Foundation/Foundation.h>
#import <sqlite3.h>
#import "Tunebook.h"
#import "Tune.h"

@class Playlist;

@interface TuneDatabase : NSObject
{
  NSMutableArray *tunes;
  NSMutableArray *playlists;
  NSMutableArray *filesToImport;
  sqlite3 *database;
  SortOrder tuneSortOrder;
  int schemaVersion;
}

@property (nonatomic, retain) NSMutableArray *tunes;
@property (nonatomic, retain) NSMutableArray *playlists;

@property (nonatomic) sqlite3 *database;

@property (nonatomic) SortOrder tuneSortOrder;

- (void)initializeDatabase;
- (void)startTransaction;
- (void)commitTransaction;

- (IBAction)removeTune:(Tune *)tune;
- (void)addTune:(Tune *)tune;
- (void)deleteAllTunes;
- (void)sortTunesBy:(SortOrder)sortOrder;

- (void)addPlaylist:(Playlist *)playlist;
- (void)removePlaylist:(Playlist *)playlist;

- (void)searchForTunes:(NSString *)searchText tunes:(NSArray *)tunelist results:(NSMutableArray *)results;
- (void)searchForTunesWithTitle:(NSString *)titleText key:(NSString *)keyText meter:(NSString *)meterText tunes:(NSArray *)tunelist results:(NSMutableArray *)results;
- (void)searchForDots:(NSString *)searchText tunes:(NSArray *)tunelist results:(NSMutableArray *)results;

- (id)tuneWithPrimaryKey:(NSInteger)pk;

- (void)createEditableCopyOfDatabaseIfNeeded;

- (void)updateTunebookSortOrder;

- (void) close;
@end
