#ifndef REPORT_SVR_H
#define REPORT_SVR_H
#include <string>

#include "report_svr/report_svr_properties.h"

namespace zsy
{
    struct ReportServerConfig
    {
        ReportServerProperties reportSvr;
    };

    inline void from_json(const nlohmann::json &j, ReportServerConfig &o)
    {
        PARSE_JSON(reportSvr, o.reportSvr);
    }

    struct ReportPassResult
    {
        struct Data
        {
            std::string carNumber;
            int type;
            std::string orderNo;
            std::string errMsg;
            std::string scene;
        };

        int code{1};
        std::string msg;
        Data data;
    };

    inline void from_json(const nlohmann::json &j, ReportPassResult::Data &o)
    {
        PARSE_JSON(car_number, o.carNumber);
        PARSE_JSON(type, o.type);
        PARSE_JSON(order_no, o.orderNo);
        PARSE_JSON(errMsg, o.errMsg);
        PARSE_JSON(scene, o.scene);
    }

    inline void from_json(const nlohmann::json &j, ReportPassResult &o)
    {
        PARSE_JSON(code, o.code);
        PARSE_JSON(msg, o.msg);
        PARSE_JSON(data, o.data);
    }

    struct ReportResult
    {
        struct Data
        {
            std::string carNumber;
            std::string orderNo;
            std::string laneCode;
        };

        int code{1};
        std::string msg;
        Data data;
    };

    inline void from_json(const nlohmann::json &j, ReportResult::Data &o)
    {
        PARSE_JSON(car_number, o.carNumber);
        PARSE_JSON(order_no, o.orderNo);
        PARSE_JSON(lane_code, o.laneCode);
    }

    inline void from_json(const nlohmann::json &j, ReportResult &o)
    {
        PARSE_JSON(code, o.code);
        PARSE_JSON(msg, o.msg);
        PARSE_JSON(data, o.data);
    }

    struct ReportData
    {
        std::optional<std::string> carNumber; // 车牌号
        std::optional<std::string> carDiscernCode; // 设备编号
        std::optional<double> weight; // 重量(kg)
        std::optional<std::string> photoFront; // 车辆正面照片URL
        std::optional<std::string> photoBody; // 车辆车身照片URL
        std::optional<std::string> weighBridgeCode;
        std::optional<std::string> telephone;
        std::optional<int> onlyCar;
        std::optional<std::string> orderNo; // 订单号
    };

    inline void to_json(nlohmann::json &j, const ReportData &o)
    {
        j = nlohmann::json{
            {"carNumber", o.carNumber},
            {"carDiscernCode", o.carDiscernCode},
            {"weight", o.weight},
            {"photoFront", o.photoFront},
            {"photoBody", o.photoBody},
            {"weighBridgeCode", o.weighBridgeCode},
            {"telephone", o.telephone},
            {"onlyCar", o.onlyCar},
            {"orderNo", o.orderNo}
        };
    }

    class ReportSvr
    {
        ReportServerProperties config;

    public:
        ReportSvr(const nlohmann::json &config);

        ReportPassResult reportPass(const std::string &license, const std::string &sn);


        ReportResult report(const std::string &license,
                            const std::string &sn,
                            const double weight,
                            const std::string &carFrontUrl,
                            const std::string &carBodyPhotoUrl,
                            const std::string &orderNo);
    };
} // zsy

#endif //REPORT_SVR_H
