/*******************************************************************************
 * Copyright 2014 Centre for Development of Advanced Computing(C-DAC), Pune
 *
 * 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 in.cdac.medinfo.csnotk.csnoserv.client;

import java.net.URI;

import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.UriBuilder;

import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.WebTarget;
import org.glassfish.jersey.client.ClientConfig;
//Logs
import in.cdac.medinfo.csnotk.csnolib.util.LoggerUtility;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
/**
 * CSNOServ Client class
 */

public class CSnoServClient {
	/**
	 * Main method
	 *
	 * @param args
	 */
	public static void main(String[] args) {
        Logger logger = LogManager.getLogger(CSnoServClient.class);
		ClientConfig config = new ClientConfig();
		Client client = ClientBuilder.newClient(config);
		WebTarget service = client.target(getBaseURI());

		// calling suggest method of the service
		logger.info(LoggerUtility.CONSOLE, service.path("api/search/suggest").queryParam("term", "head pain")
				.request(MediaType.APPLICATION_JSON).get(String.class));

		// calling search method of the service
		logger.info(LoggerUtility.CONSOLE, service.path("api/search/search").queryParam("term", "headache")
				.request(MediaType.APPLICATION_JSON).get(String.class));

	}

	/**
	 * Gets the base URI
	 *
	 * @return object of {@link URI}
	 */
	private static URI getBaseURI() {
		return UriBuilder.fromUri("http://localhost:8080/csnoserv").build();
	}

}
