#include <JaguarLite.h>
#include <iostream>


// Test simple data insert and select 
void test_simple(JaguarLite &db)
{
    db.execute("create table t1( key:  a int, value: b int )");
    
    db.startQuery("desc t1");
    db.read();
    std::string msg = db.getMessage();
    std::cout << msg << std::endl;
    db.endQuery();
    
    std::cout << std::endl;
    
    db.execute("insert into t1 values ('1', '100')");
    db.execute("insert into t1 values ('2', '200')");
    db.execute("insert into t1 values ('3', '300')");
    db.execute("insert into t1 values ('4', '400')");

    db.startQuery("select * from t1");
    while ( db.read() ) {
        db.printRow();
        std::string jsonmsg  = db.json();
        std::cout << jsonmsg << std::endl;
    }

    if ( db.hasError()) {
        std::cout << "Error: " << db.error() << std::endl;
    }
    db.endQuery();

}

// Test vector data insert and select
void test_vector(JaguarLite &db)
{
    db.execute("create store vec1 ( v vector(10, 'cosine_fraction_float'), v:text char(64) )");
    
    db.execute("insert into vec1 values ( '0.8, 0.4, 0.2, 0.3, 0.7, 0.03, 0.3, 0.41, 0.2, 0.3', ' vector data of apple' ) ");
    db.execute("insert into vec1 values ( '0.7, 0.4, 0.1, 0.3, 0.5, 0.23, 0.6, 0.51, 0.1, 0.1', ' vector data of pear' ) ");
    db.execute("insert into vec1 values ( '0.2, 0.5, 0.3, 0.4, 0.6, 0.63, 0.4, 0.61, 0.3, 0.5', ' vector data of orange' ) ");
    
    
    db.startQuery("select similarity(v, '0.1, 0.2, 0.3, 0.4, 0.5, 0.3, 0.1, 0.5, 0.01, 0.2', 'topk=3,type=cosine_fraction_float') from vec1");

    while ( db.read() ) {
        std::string jsonmsg  = db.json();
        std::cout << jsonmsg << std::endl;
    }

    if ( db.hasError()) {
        std::cout << "Error: " << db.error() << std::endl;
    }

    db.endQuery();
}



int main( int argc, char *argv[] ) 
{
    /// create or use mydb of customer1
    JaguarLite db1("mydb", "customer1");
    test_simple(db1);


    // create or use vectordb of customer2
    JaguarLite db2("myvectordb", "customer2");
    test_vector(db2);

    return 0;

}
