package cz.csu.sdmx.soap.endpoints;

import cz.csu.sdmx.dao.ValidationResultsDao;
import cz.csu.sdmx.soap.GetValidationResultRequest;
import cz.csu.sdmx.soap.GetValidationResultResponse;
import cz.csu.sdmx.soap.GetValidationResultsRequest;
import cz.csu.sdmx.soap.GetValidationResultsResponse;
import java.util.Date;
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;

@Endpoint
public class ResultEndpoint extends BaseEndpoint{
	
        @Autowired
        private ValidationResultsDao resultsDao;

	@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getValidationResultRequest")
	@ResponsePayload
	public GetValidationResultResponse getResult(@RequestPayload GetValidationResultRequest request) {
            GetValidationResultResponse response = factory.createGetValidationResultResponse();
            response.setValidationResult(resultsDao.find(request.getValidationResultID()));
            return response;
	}
        
        @PayloadRoot(namespace = NAMESPACE_URI, localPart = "getValidationResultsRequest")
	@ResponsePayload
	public GetValidationResultsResponse getResults(@RequestPayload GetValidationResultsRequest request) {
            GetValidationResultsResponse response = factory.createGetValidationResultsResponse();
            Date from = request.getDateFrom();
            Date to = request.getDateTo();
            response.getValidationResults().addAll(resultsDao.getBetween(from, to));
            return response;
	}
}
