#ifndef MODULE_ATTENDANCE_VEHICLE_H
#define MODULE_ATTENDANCE_VEHICLE_H

/**
  *@brief 车辆考勤模块
  *车辆进入某些特定区域，结束考勤；从特定区域进入其他区域，开始考勤
  *@author 戴月腾
  *@date 2018-08-07
*/

#include <memory>
#include <mutex>
#include <map>
#include <string>
#include <chrono>
#include <vector>
#include <set>
#include "module_const.h"

/**
 * @brief 车辆进入某些特定区域，结束考勤；从特定区域进入其他区域，开始考勤, 单例
 */
class module_attendance_vehicle:public singleton_base<module_attendance_vehicle>
{
private:
    friend class singleton_base<module_attendance_vehicle>;
    module_attendance_vehicle()
    {
    }

public:
    void on_enter(std::shared_ptr<card_location_base> card_ptr,std::shared_ptr<area_hover>&c,double speed)
    {
        card_ptr->m_attendance_start_time=std::chrono::system_clock::now();
    }

    void on_hover(std::shared_ptr<card_location_base> card_ptr,std::shared_ptr<area_hover>&c,double speed,
                  event_map& ev_map)
    {
        auto area_ptr = c->m_area;

        //从考勤状态转换为结束考勤
        if(AT_NOT_ATTENDANCE == area_ptr->m_area_type)
        {
            if(AS_ATTENDANCE == card_ptr->m_stat_attendance)
            {
                card_ptr->m_stat_attendance = AS_NOT_ATTENDANCE;

                //作为一条结束考勤记录保存到数据库
                tool_db::save_attendance(card_ptr);
            }
        }
        else //没在考勤状态转换为考勤状态
        {
            if(AS_ATTENDANCE != card_ptr->m_stat_attendance)
            {
                card_ptr->m_stat_attendance = AS_ATTENDANCE;

                //作为一条考勤记录保存到数据库
                tool_db::save_attendance(card_ptr);
            }
        }
    }


    void on_leave(std::shared_ptr<card_location_base> card_ptr,std::shared_ptr<area_hover>&c,double speed)
    {

    }
};
typedef std::shared_ptr<module_attendance_vehicle>  module_attendance_vehicle_ptr;

#endif // MODULE_ATTENDANCE_VEHICLE_H
