/******************************************************************************
 * Copyright 2020 The siasun Transport Authors. All Rights Reserved.
 * Author: madesheng
 * Licensed under the Apache License, Version 1.0 (the "License");
 *****************************************************************************/
#ifndef DECISIONDATABASE_H
#define DECISIONDATABASE_H


#include "ros/ros.h"
#include "../common/sqlite3helper.h"
#include "decisiondatatype.h"

namespace robot {
namespace decisionSpace {

#define DATABASE_SUCCESS     0
#define DATABASE_FAILTURE   -1

class DecisionDatabase{

public :
    DecisionDatabase(){}

    static std::string Name();
    /**
    * @brief decision模块的数据库初始化，如果相关表不存在，则建立相关的表
    * @brief 相关的表:action_directive,location_map,location_rule_info
    * @return 0失败
    */
    static int InitDB();

    /**
    * @brief 向action_Directive表中插入一条
    * @return 0失败
    */
    static int InsertActionDirective(const char* ruleName,
                              int iDirectiveID,
                              const char* directiveInfo,
                              int iDirectiveResult);

    /**
    * @brief 向location_map表中插入一条
    * @return 0失败
    */
    static int InsertLocationMap(float fLocationLon1,
                          float fLocationLat1,
                          float fLocationLon2,
                          float fLocationLat2,
                          float fLocationX1,
                          float fLocationY1,
                          const char * mapId ,
                          float fLocationX2,
                          float fLocationY2);

    /**
    * @brief 向location_rule_info表中插入一条
    *
    * @return 0失败
    */
    static int InsertLocationRuleInfo(const char * ruleName,
                               int iLocationID,
                               double dLocationLon,
                               double dLocationLat,
                               float dLocationHeight,
                               float fLocationSpeed
                               );


    /**
    * @brief 向location_rule_info表中插入一条 action_Directive表中插入一条
    * @return 0失败
    */
    static int InsertLocationRuleInfoAndActionDirective(const char* ruleName,
                                                        int iDirectiveID,
                                                        const char* directiveInfo,
                                                        int iDirectiveResult,
                                                        int iLocationID,
                                                        double dLocationLon,
                                                        double dLocationLat,
                                                        float dLocationHeight,
                                                        float fLocationSpeed);

    /**
    * @brief 在action_firective表中,
    * @brief 删除rule_name的记录
    * @return 0失败
    */
    static int DeleteActionDirective(const char* ruleName);

    /**
    * @brief 在action_firective表中,
    * @brief 删除directive_id的记录
    * @return 0失败
    */
    static int DeleteActionDirective(int iDirectiveID);

    /**
    * @brief 在location_map表中,
    * @brief 删除map_id的记录
    * @return 0失败
    */
    static int DeleteLocationMap(const char* mapID);

    /**
    * @brief 在location_rule_info表中,
    * @brief 删除rule_name的记录
    * @return 0失败
    */
    static int DeleteLocationRuleInfo(const char* RuleName);

    /**
    * @brief 在location_rule_info表中,
    * @brief 删除rule_name的记录
    * @return 0失败
    */
    static int DeleteLocationRuleInfo(int iLocationID);

    /**
    * @brief 修改rule_name和directive_id的directive_result的记录
    * @return 0失败
    */
    static int UpdateActionDirective(const char* ruleName,int iDirectiveID,int iNewDirectiveResult);

    static int UpdateLocationMap(float fNewLocationLon1,
                          float fNewLocationLat1,
                          float fNewLocationLon2,
                          float fNewLocationLat2,
                          float fNewLocationX1,
                          float fNewLocationY1,
                          float fNewLocationX2,
                          float fNewLocationY2,
                          const char * mapId);
    /**
    * @brief 按起始位置和数量查询的action_Directive的记录
    * @return 0失败
    */
    static std::vector<ACTION_DIRECTIVE> QueryActionDirective(int iStart, int iLength);

    /**
    * @brief 按起始位置和数量查询的location_rule_info的记录
    * @return 0失败
    */
    static std::vector<LOCATION_RULE_INFO> QueryLocationRuleInfo(int iStart, int iLength);


    /**
    * @brief 查询总数的action_Directive的记录
    * @return 0失败
    */
    static int countOfActionDirective();

    /**
    * @brief 查询总数的location_map的记录
    * @return 0失败
    */
    static int countOfLocationMap();

    /**
    * @brief 查询总数的location_rule_info的记录
    * @return 0失败
    */
    static int countOfLocationRuleInfo();
    };

}
}










#endif // DECISIONDATABASE_H
