package com.cico.nest.lcdp.boot.core.system.api.social;

import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import com.cico.nest.lcdp.boot.core.system.service.social.SocialClientService;
import com.cico.nest.lcdp.boot.api.system.social.SocialClientApi;
import com.cico.nest.lcdp.boot.api.system.social.dto.SocialWxJsapiSignatureRespDTO;
import com.cico.nest.lcdp.boot.api.system.social.dto.SocialWxPhoneNumberInfoRespDTO;
import com.cico.nest.lcdp.framework.common.util.object.BeanUtils;
import jakarta.annotation.Resource;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;


/**
 * 社交应用的 API 实现类
 *
 * @author zws
 */
@Service
@Validated
public class SocialClientApiImpl implements SocialClientApi {

    @Resource
    private SocialClientService socialClientService;

    @Override
    public String getAuthorizeUrl(Integer socialType, Integer userType, String redirectUri) {
        return socialClientService.getAuthorizeUrl(socialType, userType, redirectUri);
    }

    @Override
    public SocialWxJsapiSignatureRespDTO createWxMpJsapiSignature(Integer userType, String url) {
        WxJsapiSignature signature = socialClientService.createWxMpJsapiSignature(userType, url);
        return BeanUtils.toBean(signature, SocialWxJsapiSignatureRespDTO.class);
    }

    @Override
    public SocialWxPhoneNumberInfoRespDTO getWxMaPhoneNumberInfo(Integer userType, String phoneCode) {
        WxMaPhoneNumberInfo info = socialClientService.getWxMaPhoneNumberInfo(userType, phoneCode);
        return BeanUtils.toBean(info, SocialWxPhoneNumberInfoRespDTO.class);
    }

}
