package cn.hmsoft.pay.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.hmsoft.frame.util.FrameAssertUtil;
import cn.hmsoft.pay.data.dao.PayMerchantDefineDao;
import cn.hmsoft.pay.data.model.PayMerchantDefine;

@Service
public class PayMerchantService {
	@Autowired
	private PayMerchantDefineDao daoMerchant;

	public void addMerchant(PayMerchantDefine merchant) {
		FrameAssertUtil.isNotEmpty(merchant.getMerchant_id(), "支付商户名称为空");
		FrameAssertUtil.isNotEmpty(merchant.getMerchant_name(), "支付商户名称为空");
		FrameAssertUtil.isNotEmpty(merchant.getMerchant_status(), "支付商户状态为空");
		PayMerchantDefine tr = this.daoMerchant.find("merchant_name", merchant.getMerchant_name());
		FrameAssertUtil.isNull(tr, "支付商户名称 " + merchant.getMerchant_name() + " 已经存在，请重新输入");
		this.daoMerchant.insert(merchant);
	}

	public void editMerchant(PayMerchantDefine merchant) {
		FrameAssertUtil.isNotEmpty(merchant.getMerchant_id(), "支付商户名称为空");
		FrameAssertUtil.isNotEmpty(merchant.getMerchant_name(), "支付商户名称为空");
		FrameAssertUtil.isNotEmpty(merchant.getMerchant_status(), "支付商户状态为空");
		PayMerchantDefine tr = this.daoMerchant.find("merchant_name", merchant.getMerchant_name());
		if (tr != null)
			FrameAssertUtil.isEqual(tr.getMerchant_id(), merchant.getMerchant_id(),
					"支付商户 " + merchant.getMerchant_name() + " 已经存在，请重新输入");

		this.daoMerchant.update(merchant);
	}

	public void deleteMerchant(String merchant_id) {
		this.daoMerchant.delete(merchant_id);
	}
	

	public void deleteMerchantChannel(String merchant_id,String channel_id) {
		this.daoMerchant.deleteMerchantChannel(merchant_id,channel_id);
	}
	
	
}
