package com.slodon.bbc.starter.thirdParty;

import com.slodon.b2b2c.core.exception.MallException;
import com.slodon.bbc.starter.thirdParty.client.*;
import com.slodon.bbc.starter.thirdParty.constant.ThirdPartyConst;
import com.slodon.bbc.starter.thirdParty.entity.SlodonThirdPartyQrCodeRequest;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.awt.image.BufferedImage;

/**
 * 三方功能操作类
 */
public class SlodonThirdParty {
    private StringRedisTemplate stringRedisTemplate;

    public SlodonThirdParty(StringRedisTemplate stringRedisTemplate) {
        this.stringRedisTemplate = stringRedisTemplate;
    }

    /**
     * 获取小程序分享二维码
     * @param qrCodeRequest 业务参数
     * @return 二维码图片
     */
    public BufferedImage getQrCode(SlodonThirdPartyQrCodeRequest qrCodeRequest) throws Exception {
        ThirdPartyBaseClient client;
        switch (qrCodeRequest.getSource()){
            case ThirdPartyConst.MINIAPP_QRCODE_SOURCE_DOUYIN:
                //抖音
                client = new DouyinClient();
                break;
            case ThirdPartyConst.MINIAPP_QRCODE_SOURCE_ALI:
                //支付宝
                client = new AliClient();
                break;
            case ThirdPartyConst.MINIAPP_QRCODE_SOURCE_BAIDU:
                //百度
                client = new BaiduClient();
                break;
            case ThirdPartyConst.MINIAPP_QRCODE_SOURCE_WX:
                //微信
                client = new WxClient();
                break;
            default:
                throw new MallException("未知小程序");
        }
        return client.getQrCode(stringRedisTemplate,qrCodeRequest);
    }
}
