#pragma once

#include "myBase.h"

#include "mySystem.h"

#include <vector>
#include <string>
#include <map>


typedef struct 
{
    std::string name;
    std::string desc;
    std::string type_str;
    uint8_t type;
    uint16_t inf;
    void *p_data;
}stru_param_cfg_data;

typedef struct 
{
    uint8_t md5[16];
    std::map<uint8_t, std::vector<stru_param_cfg_data>> map_type_param;
    std::vector<stru_param_cfg_data> vec_param;
}stru_param_cfg;


typedef struct 
{
    std::vector<std::string> field_vec;
}stru_csv_row;

typedef struct
{
    std::vector<stru_csv_row> row_vec;
    int capacity;
}stru_csv_data;



typedef struct
{
    std::string saddr;
    std::string desc;
    uint16_t inf;
    bool invert;
    uint16_t debounce_time;
    uint8_t data;
}stru_iec_st_info;

typedef struct 
{
    std::string saddr;
    std::string desc;
    uint16_t inf;
    float factor;
    uint8_t record_flag;
    uint16_t dead_zone;
    float max_limit;
    float data;
    float old_data;
}stru_iec_mx_info;

typedef struct
{
    std::string saddr;
    std::string desc;
    uint16_t inf;
    uint16_t ctrl_attr;
    uint8_t data;
}stru_iec_co_info;


typedef struct
{
    std::string saddr;
    std::string desc;
    uint16_t inf;
    float factor;
    float data;
}stru_iec_dd_info;

typedef struct
{
    std::string saddr;
    std::string desc;
    uint16_t inf;
    uint8_t encoding;
    uint8_t type;
    uint16_t param_addr;
    uint8_t up_dtype;
    float factor;
    void *p_data;
}stru_iec_param_info;


typedef struct
{
    stru_csv_data *p_fixed_param_cfg_csv;
    stru_csv_data *p_param_csv;
    stru_csv_data *p_iec_st_csv;
    stru_csv_data *p_iec_mx_csv;
    stru_csv_data *p_iec_co_csv;
    stru_csv_data *p_iec_dd_csv;
    stru_csv_data *p_iec_param_fixed_csv;
    stru_csv_data *p_iec_param_run_csv;
    stru_csv_data *p_iec_param_act_csv;

    stru_param_cfg *p_param_cfg;
    std::map<std::string, std::string> param_signal_name_map;

    std::vector<stru_iec_st_info> st_info_vec;
    std::vector<stru_iec_mx_info> mx_info_vec;
    std::vector<stru_iec_co_info> co_info_vec;
    std::vector<stru_iec_dd_info> dd_info_vec;
    std::vector<stru_iec_param_info> param_info_vec;
}stru_app_cfg;

int parse_cfg_files();
stru_app_cfg *get_app_cfg_ptr(void);