package cn.pluss.platform.other;

/**
 * TODO
 *
 * @author crystal
 * @date 2022/5/13 16:55
 */

import cn.pluss.platform.entity.UserApp;
import cn.pluss.platform.entity.UserInfo;
import cn.pluss.platform.util.AESEncrypt;
import com.alibaba.fastjson.JSON;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.nio.charset.StandardCharsets;

/**
 * 积分商城同步用户信息参数实体类
 */
@Data
@NoArgsConstructor
public class JfShopSyncUser {

    /**
     * 登录账号
     */
    private String account;

    /**
     * 用户名称
     */
    private String nickname;

    /**
     * 商户code
     */
    private String syb_merchant_code;

    /**
     * 用户Id
     */
    private String syb_merchant_id;

    /**
     * 手机号
     */
    private String mobile;

    /**
     * 构造方法
     * @param info
     * @param userApp
     */
    public JfShopSyncUser(UserInfo info, UserApp userApp) {
        this.account = info.getLoginName();
        this.mobile = info.getPhone();
        this.syb_merchant_id = userApp.getUserId().toString();
        this.nickname = userApp.getUserName();
        this.syb_merchant_code = userApp.getMerchantCode();
    }

    public String createAesData(String pubKey) {
        String content = JSON.toJSONString(this);
        try {
            return AESEncrypt.encryptEcbToString(content.getBytes(StandardCharsets.UTF_8), pubKey.getBytes(StandardCharsets.UTF_8), null);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
