package top.imwork.commons.core.utils;

import com.alibaba.fastjson.JSONObject;
import top.imwork.commons.core.enums.HttpStatusCodeEnum;

import java.util.HashMap;
import java.util.Map;

/**
 * Copyright (C), 2015-2021
 * FileName: ObjectUtils
 * Author<作者姓名>:   stars
 * CreateTime<创建时间>:   2021/11/12 17:00
 * UpdateTime<修改时间>:   2021/11/12 17:00
 * Description〈功能简述〉:
 * History<历史描述>:
 * Since<版本号>: 1.0.0
 */
public final class ObjectUtils {
    private ObjectUtils() {
        throw new IllegalStateException("Utility class");
    }

    /**
     * 判断字符串是否为空
     *
     * @param obj 对象
     * @return true/false
     */
    public static boolean isEmpty(Object obj) {
        if (obj == null) {
            return true;
        } else if ("".equals(obj.toString().trim())) {
            return true;
        }

        return false;
    }

    public static Map<String, Object> getMap(JSONObject jsonObject) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", HttpStatusCodeEnum.OK.getCode());
        map.put("token", jsonObject.get("access_token"));
        map.put("token_type", jsonObject.get("token_type"));
        map.put("refresh_token", jsonObject.get("refresh_token"));
        map.put("expires_in", jsonObject.get("expires_in"));
        map.put("scope", jsonObject.get("scope"));
        return map;
    }
}