#ifndef METADATA_H
#define METADATA_H

#include <glib.h>

#include "bmpx/list.h"

#include <libhrel/types.h>
#include <libhrel/tuple.h>
#include <libhrel/relation.h>

// Metadata cache version
#define LCM_VERSION 1

typedef enum {
    BMP_DATUM_LOCATION,
    BMP_DATUM_TITLE,
    BMP_DATUM_ARTIST,
    BMP_DATUM_ALBUM,
    BMP_DATUM_GENRE,
    BMP_DATUM_COMMENT,
    BMP_DATUM_TIME,
    BMP_DATUM_TRACK,
    BMP_DATUM_RATING,
    BMP_DATUM_DATE,
    BMP_DATUM_MTIME,
    BMP_DATUM_BITRATE,
    BMP_DATUM_SAMPLERATE,
    BMP_DATUM_COUNT,

    BMP_DATUM_NONE
} BmpMetadatumId;

#define BMP_METADATA_PKEY BMP_DATUM_LOCATION

gchar*
bmp_metadata_get_title (BmpMetadatumId tag_id);

gchar*
bmp_metadata_get_id (BmpMetadatumId tag_id);

const gchar*
bmp_metadata_get_id_static (BmpMetadatumId tag_id);

const gchar*
bmp_metadata_get_default_char (BmpMetadatumId tag_id);

gint
bmp_metadata_get_default_int (BmpMetadatumId tag_id);

GType
bmp_metadata_get_type (BmpMetadatumId tag_id);

HTuple*
bmp_metadata_tuple_create_default (void);

G_BEGIN_DECLS

/* Metadata Cache Functions */
#define BMP_TYPE_METADATA_CACHE		  (bmp_metadata_cache_get_type ())
#define BMP_METADATA_CACHE(obj)		  (G_TYPE_CHECK_INSTANCE_CAST ((obj), BMP_TYPE_METADATA_CACHE, BmpMetadataCache))
#define BMP_METADATA_CACHE_CLASS(klass)	  (G_TYPE_CHECK_CLASS_CAST ((klass), BMP_TYPE_METADATA_CACHE, BmpMetadataCacheClass))
#define BMP_IS_METADATA_CACHE(obj)  	  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BMP_TYPE_METADATA_CACHE))
#define BMP_IS_METADATA_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BMP_TYPE_METADATA_CACHE))
#define BMP_METADATA_CACHE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), BMP_TYPE_METADATA_CACHE, BmpMetadataCacheClass))

typedef struct _BmpMetadataCache BmpMetadataCache;
typedef struct _BmpMetadataCacheClass BmpMetadataCacheClass;
typedef struct _BmpMetadataCachePrivate BmpMetadataCachePrivate;

struct _BmpMetadataCache {
	GObject parent;

        BmpMetadataCachePrivate *private;
};

struct _BmpMetadataCacheClass {
	GObjectClass parent;

	void (*file_added)	(BmpMetadataCache * self, gint _idx);
};

extern BmpMetadataCache   *bmp_metadata_cache;

GType
bmp_metadata_cache_get_type (void);

BmpMetadataCache*
bmp_metadata_cache_new (void);

HTuple*
bmp_metadata_cache_get_metadata (BmpMetadataCache *self, const gchar *uri);

gchar*
bmp_metadata_cache_get_titlestring (BmpMetadataCache *self, const gchar *uri);

/* Needed for DBus remote metadata querying */
GHashTable*
bmp_metadata_cache_get_hash_value_table (BmpMetadataCache *self, const gchar *uri);

/* Private API */
void
_bmp_metadata_cache_tuple_inserted (BmpMetadataCache *self, HTuple *tuple);
 
/* Query API */
typedef struct _QueryAtom QueryAtom;
struct _QueryAtom {
    BmpMetadatumId    tag_id;
    GValue	     *match_value;
    gboolean	      exact_match;
};

typedef struct _Query Query;
struct _Query {
    GList	     *query_atoms;
};

Query*
bmp_metadata_cache_query_construct (BmpMetadataCache *self, gint n_atoms, ...);

HRelation*
bmp_metadata_cache_query_run (BmpMetadataCache *self, Query *query); 

#endif /* METADATA_H */
