package org.sistema.spring.ws.carinsurance;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;


/**
 * The endpoint for the webservice
 * Check with : http://localhost:8080/ws/cars.wsdl
 * @author Eugenia Pérez
 *
 */
@Endpoint
public class CarInsuranceEndpoint {
	private static final String NAMESPACE_URI = 
			"http://sistema.org/spring/ws/carinsurance";

	private CarDatasource carDatasource;

	@Autowired
	public CarInsuranceEndpoint(CarDatasource carDatasource) {
		this.carDatasource = carDatasource;
	}

	/**
	 * gets insurance info using plate number
	 * @param request
	 * @return
	 */
	@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getInsuranceRequest")
	@ResponsePayload
	public GetInsuranceResponse getInsurance(@RequestPayload GetInsuranceRequest request) {
		GetInsuranceResponse response = new GetInsuranceResponse();
		response.setCar(carDatasource.findCar(request.getPlate()));

		return response;
	}
}
