#ifndef __CDDesc__H
#define __CDDesc__H

typedef struct CDTrack CDTrack;
typedef struct CDDesc CDDesc;
typedef struct CDDescList CDDescList;

#include <stdbool.h>
#include "WimpLib:Array.h"
#include "MetaData.h"
#include "CDTrack.h"

typedef enum
{ CDDescList_TypeMain   = 0    // Saved in standard location
, CDDescList_TypeSearch = 1
} CDDescList_Type;

// CD Database
CDDescList* CDDescList_Get(void);
void CDDescList_Release(void);
int CDDescList_Count(CDDescList*);
void CDDescList_ListIds(CDDescList*, Array* pList);
CDDescList_Type CDDescList_GetType(const CDDescList*);

// Find index of CD id in database
int throw_CDDescList_Find(CDDescList*, unsigned long id);

void CDDescList_StartUpdate(CDDescList*);
void CDDescList_EndUpdate(CDDescList*);
bool CDDescList_IsBusy(const CDDescList*);
void CDDescList_Show(CDDescList*, CDDesc* pDesc);

void CDDescList_SaveChanges(CDDescList*);
void CDDescList_RevertChanges(CDDescList*);

// CD search list
CDDescList*  throw_New_CDSearchList(void);
void throw_CDSearchList_Add(CDDescList*, CDTrack* pTrack);
int CDSearchList_TrackCount(CDDescList*);
CDTrack* CDSearchList_GetTrack(CDDescList*, int index);

// Get current working copy of CD description
// from index in database or from CD id if index is invalid
CDDesc* throw_CDDescList_GetWorkDesc(CDDescList*, int index, unsigned long id);

// Fix nr of tracks in descriptor and if necessary in database
void throw_CDDesc_FixCDSize(CDDesc*, int tracks);

const char* CDDesc_GetLabel(const CDDesc*);
const char* CDDesc_GetMetaString(const CDDesc*, EMetaId id);
unsigned long CDDesc_GetId(const CDDesc*);
Array* CDDesc_GetPrefList(const CDDesc*);

bool throw_CDDesc_SetMetaString(CDDesc*, EMetaId id, const char* pText);
void CDDesc_SetModifiedFlag(CDDesc*, bool bModified);
void CDDesc_SetDeletedFlag(CDDesc*, bool bDeleted);
void CDDesc_Identify(CDDesc* pDesc, int drive);

int CDDesc_CountTracks(const CDDesc*);
CDTrack* CDDesc_GetTrack(const CDDesc*, int i);
void CDDesc_RefreshViews(CDDesc* This, void* pSender, bool bModified);

#endif
