package com.ruoyi.bst.app.service.impl;

import com.ruoyi.bst.app.domain.AppConfig;
import com.ruoyi.bst.app.domain.AppVO;
import com.ruoyi.bst.app.domain.enums.AppType;
import com.ruoyi.bst.app.service.AppConverter;
import com.ruoyi.common.auth.ali.AliConfig;
import com.ruoyi.common.auth.wx.config.WxConfig;
import org.springframework.stereotype.Service;

/**
 * @author wjh
 * 2025/1/9
 */
@Service
public class AppConverterImpl implements AppConverter {
    @Override
    public WxConfig toWxConfig(AppVO app) {
        if (app == null || !AppType.WX.getType().equals(app.getType()) || app.getConfig() == null) {
            return null;
        }

        AppConfig appConfig = app.getConfig();

        WxConfig config = new WxConfig();
        config.setAppId(appConfig.getAppId());
        config.setAppSecret(appConfig.getAppSecret());
        return config;
    }

    @Override
    public AliConfig toAliConfig(AppVO app) {
        if (app == null || !AppType.WX.getType().equals(app.getType()) || app.getConfig() == null) {
            return null;
        }
        AppConfig appConfig = app.getConfig();

        AliConfig config = new AliConfig();
        config.setAppId(appConfig.getAppId());
        config.setPrivateKey(appConfig.getPrivateKey());
        config.setAesPrivateKey(appConfig.getAesPrivateKey());
        config.setAppCertPath(appConfig.getAppCertPath());
        config.setAlipayCertPath(appConfig.getAlipayCertPath());
        config.setAlipayRootCertPath(appConfig.getAlipayRootCertPath());
        return config;
    }
}
