#ifndef __CLASSIFIERDB_H__
#define __CLASSIFIERDB_H__

#include <sqlite3.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <map>
#include <string.h>

class classifierdb
{
 public:

  struct classifier_type
  {
    int id;
    std::string name;
  };
  struct feature_vec_type
  {
    int id;
    std::string des;
  };
  struct model
  {
    int id;
    int ctid;
    int fvid;
    std::string notes;
    std::string createdate;
    char *data;
    int datasize;
  };

  classifierdb();
  ~classifierdb();
  int open( std::string fn );
  int close();

  int createtables();

  /// adds a classifier type to the database
  /**
   * @param name classifier name
   * @return the assigned classifier type id or -1 if on error
   */
  int add_classifiertype( std::string &name );

  /// adds a feature vector type to the database
  /**
   * @param des the descriptor
   * @return the assigned feature vector type id or -1 if on error
   */
  int add_featurevectortype( std::string &des );

  /// adds a new model
  /**
   * @param ctid classifier type id
   * @param fvid feature vector type id
   * @param createdate the create data string YYYY/MM/DD HH:MM:SS
   * @param notes notes about this model
   * @param data the modle data
   * @param data_size the size of the data
   */
  int add_model( int ctid, int fvid, std::string &createdate,
                 std::string &notes, char *data, int data_size );

  /// adds a new model
  /**
   * @param ctid classifier type id
   * @param fvid feature vector type id
   * @param createdate the create data string YYYY/MM/DD HH:MM:SS
   */
  int add_model( int ctid, int fvid, std::string &createdate );

  int modify_model_data( int mid, char *data, int data_size );

  int modify_model_note( int mid, std::string &notes );

  int get_classifiertype( int id, classifier_type &ct );

  int get_featurevectortype( int id, feature_vec_type &vt );

  int get_model( int id, model &m );

  int all_classifiertype( std::map<int, classifier_type> &all);

  int all_featurevectortype( std::map<int, feature_vec_type> &all);

  int all_model( std::map<int, model> &all );

 private:
  int printerror( int rc );
  sqlite3 *db;
};

#endif
