#pragma once

#include <string>

#include "nlohmann/json.hpp"

namespace nsLotInfo
{
    using stLotInfo = struct
    {
        bool        LotOpened{ false };
        std::string LotName;
        std::string Recipe;
        std::string Package;
        std::string OperatorID;
        std::string ShiftID;
        std::string StartTime;
        int         LotQty{ 0 };
        // custom
    };
}

namespace nsLotInfo
{
    using namespace nlohmann;

    template <typename T>
    inline void getValue(const nlohmann::json& j, const std::string& fieldname, T& value)
    {
        if (j.contains(fieldname))
        {
            j.at(fieldname).get_to(value);
        }
    }

    void from_json(const json& j, stLotInfo& x);
    void to_json(json& j, const stLotInfo& x);

    inline void from_json(const json& j, stLotInfo& x)
    {
        getValue(j, "LotOpened", x.LotOpened);
        getValue(j, "LotName", x.LotName);
        getValue(j, "Recipe", x.Recipe);
        getValue(j, "Package", x.Package);
        getValue(j, "OperatorID", x.OperatorID);
        getValue(j, "ShiftID", x.ShiftID);
        getValue(j, "StartTime", x.StartTime);
        getValue(j, "LotQty", x.LotQty);
        //
    }

    inline void to_json(json& j, const stLotInfo& x)
    {
        j = nlohmann::json{
            { "LotOpened", x.LotOpened },
            { "LotName", x.LotName },
            { "Recipe", x.Recipe },
            { "Package", x.Package },
            { "OperatorID", x.OperatorID },
            { "ShiftID", x.ShiftID },
            { "StartTime", x.StartTime },
            { "LotQty", x.LotQty }
            //
        };
    }
}