package eu.fp7.scase.eticsbte.operationcommit.service.impl;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;

import eu.fp7.scase.eticsbte.operationcommit.service.RequestBean;
import eu.fp7.scase.eticsbte.operationcommit.service.ResponseBean;
import eu.fp7.scase.eticsbte.operationcommit.service.ServiceClient;

public class DeleteVirtualHostClient implements ServiceClient {

	private String 	hostId,
					username,
					password,
					url;
	
	@Override
	public void setParameters(RequestBean requestBean) {
		
		this.hostId = requestBean.getHostId();
		this.username = requestBean.getForemanUserName();
		this.password = requestBean.getForemanPassword();
		this.url = requestBean.getBaseUrl()+"/DeleteHost/rest/result/query";
	}

	@Override
	public ResponseBean execute(Client oJAXRSRESTClient) {
		ResponseBean response = new ResponseBean();
		WebResource oTargetResource = oJAXRSRESTClient.resource(this.url).queryParam("username", this.username).queryParam("password", this.password).queryParam("host_id", hostId);
		
		response.setoResponse(oTargetResource.type(javax.ws.rs.core.MediaType.APPLICATION_JSON).accept(javax.ws.rs.core.MediaType.APPLICATION_JSON).get(ClientResponse.class));
		
		return response;
	}

	public static void main(String[] args) {
		RequestBean bean = new RequestBean();
		bean.setBaseUrl("http://localhost:8080");
		bean.setHostId("scasefinalTestVM");
		bean.setForemanUserName("admin");
		bean.setForemanPassword("temp123!");
		DeleteVirtualHostClient client = new DeleteVirtualHostClient();
		client.setParameters(bean);
		try
		{
			client.execute(Client.create());
			
		} catch (Exception e)
		{
			e.printStackTrace();
		}
		
	}

	
}
