package org.bench4q.web.validation;

import org.bench4q.web.model.TestPlanRequestModel;
import org.bench4q.web.model.WebScriptModel;
import org.springframework.stereotype.Component;

@Component
public class TestPlanValidate {

	public ValidateResponseModel validateTestPlanSubmited(
			TestPlanRequestModel testPlanRequestModel) {
		if (testPlanRequestModel.getScriptList() == null
				|| testPlanRequestModel.getScriptList().size() == 0) {
			return new ValidateResponseModel(false, "empty script in test");
		}
		for (WebScriptModel scriptModel : testPlanRequestModel.getScriptList()) {
			if (!isValidateScriptModel(scriptModel)) {
				return new ValidateResponseModel(false, "error script config");
			}
		}
		return new ValidateResponseModel(true, "");

	}

	private boolean isValidateScriptModel(WebScriptModel scriptModel) {
		if (scriptModel.getId() == 0)
			return false;
		if (scriptModel.getLoad() == 0)
			return false;
		if (scriptModel.getExecuteRange() == 0)
			return false;
		return true;
	}
}
