package cn.hmsoft.pay.control;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.hmsoft.application.web.Ajax;
import cn.hmsoft.frame.control.FrameControl;
import cn.hmsoft.pay.data.dao.PayMerchantDefineDao;
import cn.hmsoft.pay.data.model.PayMerchantChannel;
import cn.hmsoft.pay.data.model.PayMerchantDefine;
import cn.hmsoft.pay.service.PayMerchantService;

@RestController
public class PayMerchantControl extends FrameControl {

	@Autowired
	private PayMerchantDefineDao daoMerchant;
	@Autowired
	private PayMerchantService sMerchant;

	@RequestMapping("/pay/merchant/page")
	public Ajax page(String query, Integer limit, Integer start, String order, String type) {
		return new Ajax(this.daoMerchant.pageMerchant(start, limit, query, this.getQueryOrder(order, type)));
	}

	@RequestMapping("pay/merchant/add")
	public Ajax add(final PayMerchantDefine merchant) {
		this.authAdminRole();
		this.sMerchant.addMerchant(merchant);
		return new Ajax(merchant);
	}

	@RequestMapping("pay/merchant/edit")
	public Ajax edit(final PayMerchantDefine merchant) {
		this.authAdminRole();
		this.sMerchant.editMerchant(merchant);
		return new Ajax();
	}

	@RequestMapping("pay/merchant/delete")
	public Ajax delete(String merchant_id) {
		this.authAdminRole();
		this.sMerchant.deleteMerchant(merchant_id);
		return new Ajax();
	}

	@RequestMapping("/pay/merchant/channel/list")
	public Ajax allChannel(String merchant_id) {
		return new Ajax(this.daoMerchant.list(PayMerchantChannel.class, "merchant_id", merchant_id));
	}

	@RequestMapping("pay/merchant/channel/add")
	public Ajax addChannel(final PayMerchantChannel channel) {
		this.authAdminRole();
		this.daoMerchant.insert(channel);
		return new Ajax();
	}

	@RequestMapping("pay/merchant/channel/edit")
	public Ajax editChannel(final PayMerchantChannel channel) {
		this.authAdminRole();
		this.daoMerchant.update(channel);
		return new Ajax();
	}

	@RequestMapping("pay/merchant/channel/delete")
	public Ajax deleteChannel(String merchant_id, String channel_id) {
		this.authAdminRole();
		this.sMerchant.deleteMerchantChannel(merchant_id, channel_id);
		return new Ajax();
	}

}
