package cn.hmsoft.pay.util;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import cn.hmsoft.application.SpringHelper;
import cn.hmsoft.pay.data.model.PayBill;
import cn.hmsoft.pay.data.model.PayChannelInfo;
import cn.hmsoft.pay.impl.PayChannelAbstract;
import cn.hmsoft.pay.service.PayBillService;

/****************************
 * 
 * @note 支付
 * @author revisit@126.com
 * @Company: www.hmsoft.cn
 * @create 2017年8月22日 上午11:27:46
 * @version 4.0.0
 */
public abstract class PayUtil {

	/**********************************
	 * 获取商户对应的渠道
	 */
	public static List<PayChannelInfo> listMerantChannel(String merchant_id) {
		return PayModuleConfig.GobalPayChannelInfoMap.get(merchant_id);
	}

	/**********************************
	 * 获取商户对应的渠道
	 */
	public static PayChannelAbstract getPayChannelImpl(String merchant_id, String channel_id) {
		PayChannelAbstract payImpl = PayModuleConfig.getPayImpl(merchant_id, channel_id);
		return payImpl;
	}

	/******************************
	 * 生成订单
	 * 
	 * @param merchant_id 商户编号
	 * @param channel_id 渠道编号
	 * @param customer_id 客户编号
	 * @param detail_id 学年
	 * @param order_amount 订单金额
	 * @param business_type 业务类型
	 * @param business_id 业务编号
	 * @param bill_no 订单编号
	 * @param bill_param 订单参数
	 * @return
	 */
	public static String order(String merchant_id, String channel_id, String customer_id, String detail_id, int order_amount,
			String business_type, String business_id, String bill_no, String bill_param) {
		return SpringHelper.getBean(PayBillService.class).order(merchant_id, channel_id, customer_id, detail_id, order_amount,
				business_type, business_id, bill_no, bill_param);
	}
	
	/******************************
	 * 生成订单
	 * 
	 * @param merchant_id 商户编号
	 * @param channel_id 渠道编号
	 * @param customer_id 客户编号
	 * @param order_amount 订单金额
	 * @param business_type 业务类型
	 * @param business_id 业务编号
	 * @param bill_no 订单编号
	 * @param bill_param 订单参数
	 * @return
	 */
	public static String order(String merchant_id, String channel_id, String customer_id, int order_amount,
			String business_type, String business_id, String bill_no, String bill_param) {
		return SpringHelper.getBean(PayBillService.class).order(merchant_id, channel_id, customer_id, null, order_amount,
				business_type, business_id, bill_no, bill_param);
	}

	/******************************
	 * 生成订单
	 * 
	 * @param merchant_id 商户编号
	 * @param channel_id 渠道编号
	 * @param customer_id 客户编号
	 * @param order_amount 订单金额
	 * @param business_type 业务类型
	 * @param business_id 业务编号
	 * @param bill_no 订单编号
	 * @return
	 */
	public static String order(String merchant_id, String channel_id, String customer_id, int order_amount,
			String business_type, String business_id, String bill_no) {
		return order(merchant_id, channel_id, customer_id, order_amount, business_type, business_id, bill_no, null);
	}

	/******************************
	 * 生成订单
	 * 
	 * @param merchant_id 商户编号
	 * @param channel_id 渠道编号
	 * @param customer_id 客户编号
	 * @param order_amount 订单金额
	 * @param business_type 业务类型
	 * @param business_id 业务编号
	 * @return
	 */
	public static String order(String merchant_id, String channel_id, String customer_id, int order_amount,
			String business_type, String business_id) {
		return order(merchant_id, channel_id, customer_id, order_amount, business_type, business_id, null, null);
	}

	/******************************
	 * 生成订单
	 * 
	 * @param merchant_id 商户编号
	 * @param channel_id 渠道编号
	 * @param customer_id 客户编号
	 * @param order_amount 订单金额
	 * @param business_id 业务编号
	 * @return
	 */
	public static String order(String merchant_id, String channel_id, String customer_id, int order_amount,
			String business_id) {
		return order(merchant_id, channel_id, customer_id, order_amount, PayParamUtil.DefaultBusinessType, business_id,
				null, null);

	}

	/********************
	 * 银行回传支付消息
	 * 
	 * @param merchant_id
	 * @param channel_id
	 * @param request
	 * @return
	 */
	public static PayBill reply(String bill_id, HttpServletRequest request,
			Map<String, Object> paramMap) {
		return SpringHelper.getBean(PayBillService.class).reply(Integer.parseInt(bill_id), request,paramMap);

	}

	/********************
	 * 查询订单
	 */
	public static PayBill query(int bill_id) {
		return SpringHelper.getBean(PayBillService.class).queryBill(bill_id);
	}
	
	/********************
	 * 订单确认
	 */
	public static PayBill check(int bill_id) {
		return SpringHelper.getBean(PayBillService.class).checkBill(bill_id);
	}
}
