#ifndef _YASL_SETTINS_H
#define _YASL_SETTINS_H

#include <time.h>
#include <map>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
#include "common_tool.h"
#include "service_position.h"

// 系统设置,,读取DB.dat_setting
struct  SSys_setting // system_limit_setting
{
	unsigned int over_count_person; // 井下人员超员
	unsigned int over_count_vehicle; // 井下车辆超员
	unsigned int over_time_person; // 井下人员超时
	unsigned int over_time_vehicle; // 井下车辆超时
	double over_speed; // 井下车辆超速

	// 考勤偏移时间
	int att_starttime_offset_staff;
	int att_endtime_offset_staff;
	int att_starttime_offset_vehicle;
	int att_endtime_offset_vehicle; 
	uint64_t att_person_thre_hour;
	//车辆防追尾配置数据
	double rear_end_d;
	time_t rear_end_t;
	double geofault_warn_dis;
    std::string rav_disable;
    std::map<int, float> mp_anti_collision;

    SSys_setting()
    {
        init();
    }
    bool check_rav(uint8_t type,uint32_t id)
    {
        bool f = false;
        std::string cardid=tool_other::type_id_to_str(type,id);
        if(rav_disable.find(cardid) != std::string::npos) 
            f=true;
        return f;
    }
    void init()
    {
        over_count_person = 1000;
        over_count_vehicle = 100;
        over_speed = 30;
        over_time_person = 36000;
        over_time_vehicle = 18000;
        att_endtime_offset_staff = 600;
        att_endtime_offset_vehicle = 600;
        att_starttime_offset_staff = 900;
        att_starttime_offset_vehicle = 600;
        att_person_thre_hour = 0;
        rear_end_d = 0;
        rear_end_t = 0;
        geofault_warn_dis=50; 
    }

    void init_anti_coll_value(const std::string& ctx)
    {
        std::string c = ctx;
        std::vector<std::string> vt;
        boost::split(vt, c, boost::is_any_of(","));

        for(size_t i = 0;i < vt.size(); ++i)
        {
            mp_anti_collision.insert(std::make_pair(i, atof(vt[i].c_str())));
        }
    }

    bool del_anti_coll_value()
    {
        mp_anti_collision.clear();
        return mp_anti_collision.empty();
    }
};

class CYaSetting
{
public:
    /*
    * 从数据库的dat_setting表初始化系统阈值,
    * 包括:井下人员阈值,井下车辆阈值,人员超时阈值,车辆超时阈值,车辆超速阈值
    */
    static SSys_setting m_sys_setting;
    static bool Init_sys_setting();
};

struct ios_service{
    static service_position_ptr m_ios_service;
    static void start_service_position(const int& port);
};

#endif