/*
 * Copyright 2019 EPAM Systems
 *
 * 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.
 */

package com.epam.ta.reportportal.ws.model;

import com.epam.ta.reportportal.ws.annotations.In;
import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.Set;

import static com.epam.ta.reportportal.ws.model.ValidationConstraints.MAX_PARAMETERS_LENGTH;

/**
 * Finishes some entity execution in Report Portal<br>
 * May be Launch, TestSuite, Test, TestStep
 *
 * @author Andrei Varabyeu
 */
@JsonInclude(Include.NON_NULL)
public class FinishExecutionRQ {

	@NotNull
	@JsonProperty(value = "endTime", required = true)
	@JsonAlias({ "endTime", "end_time" })
	@ApiModelProperty(required = true)
	private Date endTime;

	@JsonProperty(value = "status")
	@In(allowedValues = { "passed", "failed", "stopped", "skipped", "interrupted", "cancelled" })
	@ApiModelProperty(allowableValues = "PASSED, FAILED, STOPPED, SKIPPED, RESETED, CANCELLED")
	private String status;

	@JsonProperty(value = "description")
	private String description;

	@Size(max = MAX_PARAMETERS_LENGTH)
	@Valid
	@JsonProperty
	@JsonAlias({ "attributes", "tags" })
	private Set<ItemAttributesRQ> attributes;

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Set<ItemAttributesRQ> getAttributes() {
		return attributes;
	}

	public void setAttributes(Set<ItemAttributesRQ> attributes) {
		this.attributes = attributes;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@Override
	public String toString() {
		final StringBuilder sb = new StringBuilder("FinishExecutionRQ{");
		sb.append("endTime=").append(endTime);
		sb.append(", description=").append(description).append("\'");
		sb.append(", attributes").append(attributes).append("\'");
		sb.append(", status='").append(status).append('\'');
		sb.append('}');
		return sb.toString();
	}

}
@@ -1956,16 +1956,82 @@
 ption;%0A%0A
+%09@JsonProperty(value = %22testCaseId%22)%0A%09private String testCaseId;%0A%0A
 %09@Size(m
@@ -2303,32 +2303,174 @@
 escription;%0A%09%7D%0A%0A
+%09public String getTestCaseId() %7B%0A%09%09return testCaseId;%0A%09%7D%0A%0A%09public void setTestCaseId(String testCaseId) %7B%0A%09%09this.testCaseId = testCaseId;%0A%09%7D%0A%0A
 %09public Set%3CItem
@@ -3011,16 +3011,71 @@
 dTime);%0A
+%09%09sb.append(%22, status='%22).append(status).append('%5C'');%0A
 %09%09sb.app
@@ -3093,16 +3093,17 @@
 ription=
+'
 %22).appen
@@ -3116,36 +3116,36 @@
 ription).append(
-%22%5C'%22
+'%5C''
 );%0A%09%09sb.append(%22
@@ -3150,38 +3150,40 @@
 (%22, 
-attributes%22).append(attributes
+testCaseId='%22).append(testCaseId
 ).ap
@@ -3191,12 +3191,12 @@
 end(
-%22%5C'%22
+'%5C''
 );%0A%09
@@ -3205,32 +3205,35 @@
 b.append(%22, 
-statu
+attribute
 s=
-'
 %22).append(st
@@ -3230,35 +3230,26 @@
 .append(
-status).append('%5C''
+attributes
 );%0A%09%09sb.
@@ -3288,10 +3288,9 @@
 g();%0A%09%7D%0A
-%0A
 %7D

Test case id added on test item finish request