/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 org.springblade.modules.nh.factory.aiswei.util;

/**
 * Client
 */
public class Client {
    /**
     * 发送请求
     *
     * @param aisweiRequest request对象
     * @return Response
     */
    public static AisweiResponse execute(AisweiRequest aisweiRequest) {
    	try {
			switch (aisweiRequest.getMethod()) {
				case GET:
					return HttpUtil.httpGet(aisweiRequest.getHost(), aisweiRequest.getPath(),
							aisweiRequest.getTimeout(),
							aisweiRequest.getHeaders(),
							aisweiRequest.getQuerys(),
							aisweiRequest.getSignHeaderPrefixList(),
							aisweiRequest.getAppKey(), aisweiRequest.getAppSecret());
				case POST_FORM:
					return HttpUtil.httpPost(aisweiRequest.getHost(), aisweiRequest.getPath(),
							aisweiRequest.getTimeout(),
							aisweiRequest.getHeaders(),
							aisweiRequest.getQuerys(),
							aisweiRequest.getBodys(),
							aisweiRequest.getSignHeaderPrefixList(),
							aisweiRequest.getAppKey(), aisweiRequest.getAppSecret());
				case POST_STRING:
					return HttpUtil.httpPost(aisweiRequest.getHost(), aisweiRequest.getPath(),
							aisweiRequest.getTimeout(),
							aisweiRequest.getHeaders(),
							aisweiRequest.getQuerys(),
							aisweiRequest.getStringBody(),
							aisweiRequest.getSignHeaderPrefixList(),
							aisweiRequest.getAppKey(), aisweiRequest.getAppSecret());
				case POST_BYTES:
					return HttpUtil.httpPost(aisweiRequest.getHost(), aisweiRequest.getPath(),
							aisweiRequest.getTimeout(),
							aisweiRequest.getHeaders(),
							aisweiRequest.getQuerys(),
							aisweiRequest.getBytesBody(),
							aisweiRequest.getSignHeaderPrefixList(),
							aisweiRequest.getAppKey(), aisweiRequest.getAppSecret());
				case PUT_STRING:
					return HttpUtil.httpPut(aisweiRequest.getHost(), aisweiRequest.getPath(),
							aisweiRequest.getTimeout(),
							aisweiRequest.getHeaders(),
							aisweiRequest.getQuerys(),
							aisweiRequest.getStringBody(),
							aisweiRequest.getSignHeaderPrefixList(),
							aisweiRequest.getAppKey(), aisweiRequest.getAppSecret());
				case PUT_BYTES:
					return HttpUtil.httpPut(aisweiRequest.getHost(), aisweiRequest.getPath(),
							aisweiRequest.getTimeout(),
							aisweiRequest.getHeaders(),
							aisweiRequest.getQuerys(),
							aisweiRequest.getBytesBody(),
							aisweiRequest.getSignHeaderPrefixList(),
							aisweiRequest.getAppKey(), aisweiRequest.getAppSecret());
				case DELETE:
					return HttpUtil.httpDelete(aisweiRequest.getHost(), aisweiRequest.getPath(),
							aisweiRequest.getTimeout(),
							aisweiRequest.getHeaders(),
							aisweiRequest.getQuerys(),
							aisweiRequest.getSignHeaderPrefixList(),
							aisweiRequest.getAppKey(), aisweiRequest.getAppSecret());
				default:
					throw new IllegalArgumentException(String.format("unsupported method:%s", aisweiRequest.getMethod()));
			}
		} catch (Exception ex) {
    		throw new RuntimeException(ex);
		}
    }
}
