package com.neusoft.smart.pos.payment.service;

import com.neusoft.smart.pos.constants.DictionaryConstant;
import com.neusoft.smart.pos.dto.payment.response.PostMchInfoResponse;
import com.neusoft.smart.pos.framework.exception.BusinessCommonException;
import com.neusoft.smart.pos.payment.constants.PaymentErrorCode;

import com.neusoft.smart.pos.payment.repository.MchPayInfoRepository;
import lombok.val;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service("mchService")
public class MchService {

	@Autowired
    private MchPayInfoRepository mchPayInfoRepository;

    /**
     * 第三方支付单生成方法
     * @return
     */
    public PostMchInfoResponse createMchInfo(String mchName, String applyType) {
        //1.校验商户名称是否合法
        if(StringUtils.isEmpty(mchName)){
            throw new BusinessCommonException(PaymentErrorCode.MCH_NAME_NOT_EMPTY);
        }
        //2.校验申请类型是否合法
        if(StringUtils.isEmpty(applyType)){
            throw new BusinessCommonException(PaymentErrorCode.MCH_APPLY_TYPE_NOT_EMPTY);
        }
        //3.存储商户信息
        val postMchInfoResponse = new PostMchInfoResponse();
        DictionaryConstant dict = DictionaryConstant.getEnumByCode(DictionaryConstant.PAYMENT_APPLY_TYPE.getCode(),applyType);
        switch (dict){
            case PAYMENT_APPLY_TYPE_NB:
                val mchPayInfo = mchPayInfoRepository.createMchPayInfo(0,mchName,applyType,DictionaryConstant.PAYMENT_MCH_STATUS_SHTG.getCode());
                BeanUtils.copyProperties(mchPayInfo,postMchInfoResponse);
                break;
            case PAYMENT_APPLY_TYPE_GR:
                break;
            case PAYMENT_APPLY_TYPE_GS:
                break;
        }
        return postMchInfoResponse;
    }

}
