package com.tzy.common.utils;

import com.tzy.common.dto.InDto;
import lombok.extern.slf4j.Slf4j;

/**
 * 用户类型
 */
@Slf4j
public class UserType {
    //微信公众号
    public static String WX_WEB = "WX_WEB";
    //微信小程序
    public static String WX_APPLET = "WX_APPLET";
    //第三方
    public static String THIRD = "THIRD";
    //第三方-安卓
    public static String THIRD_APK = "THIRD_APK";
    //第三方-ios
    public static String THIRD_APP = "THIRD_APP";
    //苹果授权登陆
    public static String APPLE_AUTH = "APPLE_AUTH";
    //微信授权登陆
    public static String WX_AUTH = "WX_AUTH";
    //角色
    public static final String USER_ROLE_SHIPPING = "shipping";
    public static final String USER_ROLE_GENERAL_USER = "general_user";
    public static final String USER_ROLE_ADMIN = "admin";

    // 拼团 publicity
    public static final String USER_ROLE_PUBLICITY = "merchant_sub_publicity";
    // 物流 delivery
    public static final String USER_ROLE_DELIVERY = "merchant_sub_delivery";

    // 主播
    public static final String USER_ROLE_LIVING = "living";
    //运营
    public static final String USER_ROLE_OPERATE_USER = "operate_user";
    //生态购操作权限
    public static final String USER_ROLE_MERCHANT_OPERATE_CODE = "merchant_operate_code";
    //生态购角色-入库
    public static final String USER_ROLE_ECOLOGICAL_SHOPPING = "ecological_shopping";
    public static boolean checkAuth(InDto inDto) {
        if (null == inDto) return false;
        if (StringUtils.isEmpty(inDto.getUserType())) return false;
        String userType = inDto.getUserType();
        log.debug("校验信息:{}", inDto);
        if ((WX_WEB.equals(userType) || WX_APPLET.equals(userType)) && StringUtils.isEmpty(inDto.getUnionid())) {
            //判断是否微信小程序或者微信公众号登陆，且判断参数是否正确
            return false;
        } else if (userType.startsWith(THIRD) && StringUtils.isEmpty(inDto.getUsername())) {
            //判断是否第三方登陆（THIRD）
            return false;
        } else if (WX_AUTH.equals(userType) && StringUtils.isEmpty(inDto.getUnionid())) {
            //判断是否微信授权登陆
            return false;
        } else if (APPLE_AUTH.equals(userType) && StringUtils.isEmpty(inDto.getUnionid())) {
            //ios
            return false;
        }
        return true;
    }


    public static void main(String[] args) {
        InDto inDto = new InDto();
        inDto.setUnionid("1111");
        inDto.setUserType("APPLE_AUTH");
        System.out.println(checkAuth(inDto));
    }
}
