#pragma once

#include <string>
#include <chrono>
#include <vector>
#include <assert.h>
#include <memory>
#include <fstream>
#include "opencv2/opencv.hpp"

using namespace std;
using namespace std::chrono;

class parambase
{
public:
    string name;
    string help;
    string strval;
    parambase(){}
    virtual  ~parambase(){}
    virtual bool set(const char* value) {return true;};
};

/**
 * 
 */
class EnginePar
{
public:
    static int cs_timeout; //кŷɵĳʱʱ(ĬһνкŴһ,Ĭֵ5)
    static int cs_detecthandsup_time; //кźֵʱ(Ĭ10s)
    static int cs_detecthandsup_interval ; //кźֵʱ(Ĭ11)
    static int cs_detectsmile_interval; //кź΢Цʱ(Ĭ11)
    static int cs_detectspeech_interval;//кźʱ(Ĭ20)
    static int cs_detectpose_interval;  //кź̬ʱ(Ĭ51)
    static int detectpose_interval;     //ǽкڼ̬ʱ(Ĭ51)
    static int detectsmile_interval;    //ǽкڼ΢Цʱ(Ĭ11)
    static int detectappearance_interval; //װ
    static float action_turnpen_thrd;   //תֵ
    static float action_turnchair_thrd; //תֵ
    static float action_record_time;    //¼ʱ
    static float sit_supporthead_thrd;  //ͷֵ
    static float sit_layondesk_thrd;    //ſֵ
    static float sit_relyingonchair_thrd;//ֵ
    static string log_path;
    static string log_level;
    static string temp_path;
	static bool set(const char* key, const char* val);
	static bool haskey(const char* key);
	static const char* getvalue(const char* key);
};
/**
 * ͷ
 */
enum VideoScene
{
    SCENE_counter,    // ̨
    SCENE_financial,   // 
    SCENE_lobby,       // 
    SCENE_hall             // 
};
/**
 * ͷ
 */
class VideoPar
{
private:
    vector<shared_ptr<parambase>> params;
public:
    VideoScene scene;            //: 1̨, 2, 3, 4(װ)
    bool audio_enable ;          //Ƶ 1,0
    int audio_channels ;         //Ƶͨ 0,1,2,4,6
    int audio_sample_rate ;      //  44100, 48000, 96000, 192000
    bool video_enable ;          // Ƶ 1,0
    //int video_analyse_rate ;   //Ƶ: >0,ÿ֡
    bool video_sample_keyframe;  //ֻؼ֡
    bool video_record;           //¼Ƶ 1,0
    int video_record_duration;   //Ƶ¼ʱ,Ĭ10s
    int video_record_reviewtime; //Ƶ¼ƻʱ,Ĭ5s
    int face_minsize;            //СС
    VideoPar();
    //~VideoPar();
    bool set(const char* key, const char* val);
    static bool haskey(const char* key);
};

template<class T>
inline int64_t NowTime()
{
	return std::chrono::time_point_cast<T>(std::chrono::system_clock::now()).time_since_epoch().count();
}

/**--------------------------------- modelsģõķ ---------------------------------**/

inline bool detectFileExist(char *file_path) {
    std::ifstream _ifstream;
    _ifstream.open(file_path, std::ios::in);
    if (!_ifstream) {
        return false;
    }
    _ifstream.close();
    return true;
}

// 任xyת
inline cv::Mat_<double> rotate_point(cv::Mat_<double> xy, double angle) {
    cv::Mat rotate_matrix = (cv::Mat_<double>(2, 2) << cos(angle), -sin(angle), sin(angle), cos(angle));
    cv::transpose(rotate_matrix, rotate_matrix);
    auto rotate_xy = xy * rotate_matrix;
    return rotate_xy;
}

// Ƿڿ
inline bool check_point_in_rect(cv::Point point, cv::Rect rect) {
    if ((rect.x < point.x && point.x < rect.x + rect.width) &&
        (rect.y < point.y && point.y < rect.y + rect.height)) {
        return true;//rectڲ
    } else {
        return false;//rectϻⲿ
    }
}

