/*
 * Copyright 2009-2017 Alibaba Cloud All rights reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <alibabacloud/dataworks-public/model/GetTopicInfluenceResult.h>
#include <json/json.h>

using namespace AlibabaCloud::Dataworks_public;
using namespace AlibabaCloud::Dataworks_public::Model;

GetTopicInfluenceResult::GetTopicInfluenceResult() :
	ServiceResult()
{}

GetTopicInfluenceResult::GetTopicInfluenceResult(const std::string &payload) :
	ServiceResult()
{
	parse(payload);
}

GetTopicInfluenceResult::~GetTopicInfluenceResult()
{}

void GetTopicInfluenceResult::parse(const std::string &payload)
{
	Json::Reader reader;
	Json::Value value;
	reader.parse(payload, value);
	setRequestId(value["RequestId"].asString());
	auto dataNode = value["Data"];
	if(!dataNode["TopicId"].isNull())
		data_.topicId = std::stol(dataNode["TopicId"].asString());
	auto allInfluencesNode = dataNode["Influences"]["InfluencesItem"];
	for (auto dataNodeInfluencesInfluencesItem : allInfluencesNode)
	{
		Data::InfluencesItem influencesItemObject;
		if(!dataNodeInfluencesInfluencesItem["BaselineId"].isNull())
			influencesItemObject.baselineId = std::stol(dataNodeInfluencesInfluencesItem["BaselineId"].asString());
		if(!dataNodeInfluencesInfluencesItem["Bizdate"].isNull())
			influencesItemObject.bizdate = std::stol(dataNodeInfluencesInfluencesItem["Bizdate"].asString());
		if(!dataNodeInfluencesInfluencesItem["InGroupId"].isNull())
			influencesItemObject.inGroupId = std::stoi(dataNodeInfluencesInfluencesItem["InGroupId"].asString());
		if(!dataNodeInfluencesInfluencesItem["BaselineName"].isNull())
			influencesItemObject.baselineName = dataNodeInfluencesInfluencesItem["BaselineName"].asString();
		if(!dataNodeInfluencesInfluencesItem["Owner"].isNull())
			influencesItemObject.owner = dataNodeInfluencesInfluencesItem["Owner"].asString();
		if(!dataNodeInfluencesInfluencesItem["Status"].isNull())
			influencesItemObject.status = dataNodeInfluencesInfluencesItem["Status"].asString();
		if(!dataNodeInfluencesInfluencesItem["ProjectId"].isNull())
			influencesItemObject.projectId = std::stol(dataNodeInfluencesInfluencesItem["ProjectId"].asString());
		if(!dataNodeInfluencesInfluencesItem["Priority"].isNull())
			influencesItemObject.priority = std::stoi(dataNodeInfluencesInfluencesItem["Priority"].asString());
		if(!dataNodeInfluencesInfluencesItem["Buffer"].isNull())
			influencesItemObject.buffer = std::stol(dataNodeInfluencesInfluencesItem["Buffer"].asString());
		data_.influences.push_back(influencesItemObject);
	}
	if(!value["Success"].isNull())
		success_ = value["Success"].asString() == "true";
	if(!value["ErrorCode"].isNull())
		errorCode_ = value["ErrorCode"].asString();
	if(!value["ErrorMessage"].isNull())
		errorMessage_ = value["ErrorMessage"].asString();
	if(!value["HttpStatusCode"].isNull())
		httpStatusCode_ = std::stoi(value["HttpStatusCode"].asString());

}

int GetTopicInfluenceResult::getHttpStatusCode()const
{
	return httpStatusCode_;
}

GetTopicInfluenceResult::Data GetTopicInfluenceResult::getData()const
{
	return data_;
}

std::string GetTopicInfluenceResult::getErrorCode()const
{
	return errorCode_;
}

std::string GetTopicInfluenceResult::getErrorMessage()const
{
	return errorMessage_;
}

bool GetTopicInfluenceResult::getSuccess()const
{
	return success_;
}

