package org.bench4q.master.domain.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.xml.bind.JAXBException;

import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;

@Entity
@Table(name = "TestPlanScriptResult")
public class TestPlanScriptResult {
//	private int testPlanId;
//	private int scriptId,
	private int id;
	private TestPlanScript testPlanScript;
	private String resultContent;
	private String resultType;
	private Date createDatetime;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id", nullable = false)
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@ManyToOne
	@JoinColumn(name = "testPlanScriptId", nullable = false)
	public TestPlanScript getTestPlanScript() {
		return testPlanScript;
	}

	public void setTestPlanScript(TestPlanScript testPlanScript) {
		this.testPlanScript = testPlanScript;
	}

	@Column(name = "resultContent", columnDefinition = "LONGTEXT", nullable = false)
	public String getResultContent() {
		return resultContent;
	}

	public void setResultContent(String scriptBriefResultContent) {
		this.resultContent = scriptBriefResultContent;
	}

	@Column(name = "resultType", columnDefinition = "TEXT", nullable = false)
	public String getResultType() {
		return resultType;
	}

	public void setResultType(String resultType) {
		this.resultType = resultType;
	}

	@Column(name = "createDatetime", nullable = false)
	public Date getCreateDatetime() {
		return createDatetime;
	}

	public void setCreateDatetime(Date createDatetime) {
		this.createDatetime = createDatetime;
	}

	public ScriptBriefResultModel extractScriptBriefResultModel() {
		try {
			return (ScriptBriefResultModel) MarshalHelper.unmarshal(
					ScriptBriefResultModel.class, this.getResultContent());
		} catch (JAXBException e) {
			return null;
		}
	}
}
