/**
  * @project shutter_verify
  * @brief   $BRIEF$
  * @author  lz
  * @data    2023/4/13
 **/
#pragma once

#include "json/json.h"

class lidarsJsonConfig {
public:
    struct NetConfig {
        std::string ip_address;
        int port;

        void info() {
            printf("---Debug %s %d : ip_address %s .\n", __func__, __LINE__, ip_address.c_str());
            printf("---Debug %s %d : port %d .\n", __func__, __LINE__, port);
        }
    };
    struct ScanBoxLimit {
        int dist_limit;
        double minx;
        double maxx;
        double miny;
        double maxy;

        void info() {
            printf("---Debug %s %d : minx %f .\n", __func__, __LINE__, minx);
            printf("---Debug %s %d : maxx %f .\n", __func__, __LINE__, maxx);
            printf("---Debug %s %d : miny %f .\n", __func__, __LINE__, miny);
            printf("---Debug %s %d : maxy %f .\n", __func__, __LINE__, maxy);
        }
    };
    struct LidarConfig {
        double angle_min;
        double angle_max;
        double angle_increment;
        double time_increment;
        int range_min;
        int range_max;
        NetConfig net_config;
        ScanBoxLimit scan_box_limit;

        void info() {
            printf("---Debug %s %d : angle_min %f .\n", __func__, __LINE__, angle_min);
            printf("---Debug %s %d : angle_max %f .\n", __func__, __LINE__, angle_max);
            printf("---Debug %s %d : angle_increment %f .\n", __func__, __LINE__, angle_increment);
            printf("---Debug %s %d : time_increment %f .\n", __func__, __LINE__, time_increment);
            printf("---Debug %s %d : range_min %d .\n", __func__, __LINE__, range_min);
            printf("---Debug %s %d : range_max %d .\n", __func__, __LINE__, range_max);
            net_config.info();
            scan_box_limit.info();
        }
    };
public:
    explicit lidarsJsonConfig(std::string path);

    ~lidarsJsonConfig() = default;

    bool getLidarConfig(int ordinal, LidarConfig &lidarconfig);

    bool getNetConfig(int ordinal, NetConfig &net_config);

    bool getScanBoxLimit(int ordinal, ScanBoxLimit &scan_box_limit);

    double angle_min(int ordinal);

    double angle_max(int ordinal);

    double angle_increment(int ordinal);

    double time_increment(int ordinal);

    int range_min(int ordinal);

    int range_max(int ordinal);

    std::string ip_address(int ordinal);

    int port(int ordinal);

    int dist_limit(int ordinal);

    double minx(int ordinal);

    double maxx(int ordinal);

    double miny(int ordinal);

    double maxy(int ordinal);

    bool update();

private:
    std::string m_path;
    Json::Value m_config;
};
