// Copyrigth Xtooltech @ 2023- All rights reserved.(LXH)

#include "ReportRecord.hpp"
#include "cJSON.h"

namespace otx {
	namespace jidu {

		ReportRecord::ReportRecord() {
			this->mTestBlockTotalNum = 0;
			this->mTestItemTotalNum = 0;
		}

		std::string ReportRecord::getSerialNo() { return this->mSerialNo; }
		void ReportRecord::setSerialNo(const std::string& v) { this->mSerialNo = v; }

		std::string ReportRecord::getMixNo() { return this->mMixNo; }
		void ReportRecord::setMixNo(const std::string& v) { this->mMixNo = v; }

		std::string ReportRecord::getVehicleType() { return this->mVehicleType; }
		void ReportRecord::setVehicleType(const std::string& v) { this->mVehicleType = v; }

		std::string ReportRecord::getVin() { return this->mVin; }
		void ReportRecord::setVin(const std::string& v) { this->mVin = v; }

		std::string ReportRecord::getStation() { return this->mStation; }
		void ReportRecord::setStation(const std::string& v) { this->mStation = v; }

		std::string ReportRecord::getReworkStation() { return this->mReworkStation; }
		void ReportRecord::setReworkStation(const std::string& v) { this->mReworkStation = v; }

		size_t ReportRecord::getTestBlockTotalNum() { return this->mTestBlockTotalNum; }
		void ReportRecord::setTestBlockTotalNum(size_t v) { this->mTestBlockTotalNum = v; }

		size_t ReportRecord::getTestItemTotalNum() { return this->mTestItemTotalNum; }
		void ReportRecord::setTestItemTotalNum(size_t v) { this->mTestItemTotalNum = v; }

		std::string ReportRecord::getResultType() { return this->mResultType; }
		void ReportRecord::setResultType(const std::string& v) { this->mResultType = v; }

		std::string ReportRecord::getCell() { return this->mCell; }
		void ReportRecord::setCell(const std::string& v) { this->mCell = v; }

		std::string ReportRecord::getTestTimeUtc() { return this->mTestTimeUtc; }
		void ReportRecord::setTestTimeUtc(const std::string& v) { this->mTestTimeUtc = v; }

		std::string ReportRecord::getExecutionTimeUtc() { return this->mExecutionTimeUtc; }
		void ReportRecord::setExecutionTimeUtc(const std::string& v) { this->mExecutionTimeUtc = v; }

		std::string ReportRecord::toJsonString() {
			// 不能包括{}。
			std::string result;

			cJSON* obj = cJSON_CreateObject();

			if (this->mSerialNo.size() > 0) {
				cJSON_AddStringToObject(obj, "serialNo", this->mSerialNo.c_str());
			}

			if (this->mMixNo.size() > 0) {
				cJSON_AddStringToObject(obj, "mixNo", this->mMixNo.c_str());
			}

			if (this->mVehicleType.size() > 0) {
				cJSON_AddStringToObject(obj, "vehicleType", this->mVehicleType.c_str());
			}

			if (this->mVin.size() > 0) {
				cJSON_AddStringToObject(obj, "vin", this->mVin.c_str());
			}

			if (this->mStation.size() > 0) {
				cJSON_AddStringToObject(obj, "station", this->mStation.c_str());
			}

			if (this->mReworkStation.size() > 0) {
				cJSON_AddStringToObject(obj, "reworkStation", this->mReworkStation.c_str());
			}

			if (this->mTestBlockTotalNum >= 0) {
				cJSON_AddStringToObject(obj, "testBlockTotalNum", std::to_string(this->mTestBlockTotalNum).c_str());
			}

			if (this->mTestItemTotalNum > 0) {
				cJSON_AddStringToObject(obj, "testItemTotalNum", std::to_string(this->mTestItemTotalNum).c_str());
			}

			if (this->mResultType.size() > 0) {
				cJSON_AddStringToObject(obj, "resultType", this->mResultType.c_str());
			}

			if (this->mCell.size() > 0) {
				cJSON_AddStringToObject(obj, "cell", this->mCell.c_str());
			}

			if (this->mExecutionTimeUtc.size() > 0) {
				cJSON_AddStringToObject(obj, "executionTimeUtc", this->mExecutionTimeUtc.c_str());
			}

			if (this->mTestTimeUtc.size() > 0) {
				cJSON_AddStringToObject(obj, "testTimeUtc", this->mTestTimeUtc.c_str());
			}

			char* tepm = cJSON_PrintUnformatted(obj);
			cJSON_Delete(obj);
			result = tepm;
			cJSON_free(tepm);

			return result;
		}

	} // namespace jidu
} // namespace otx
