package com.atmob.mobile_use_statistics.utils;

import java.util.Map;

import io.flutter.plugin.common.MethodCall;

public class ParamUtil {


    public static String getString(Map<String, Object> map, String key) {
        if (map == null) {
            return null;
        }
        if (!map.containsKey(key)) {
            return null;
        }
        return (String) map.get(key);
    }

    public static Integer getInt(Map<String, Object> map, String key) {
        if (map == null) {
            return null;
        }
        if (!map.containsKey(key)) {
            return null;
        }
        Object value = map.get(key);
        if (value == null) {
            return null;
        }
        return (int) value;
    }

    public static Double getDouble(Map<String, Object> map, String key) {
        if (map == null) {
            return null;
        }
        if (!map.containsKey(key)) {
            return null;
        }
        Object value = map.get(key);
        if (value == null) {
            return null;
        }
        return (double) value;
    }

    public static double getDouble(Map<String, Object> map, String key, double defaultValue) {
        Double d = getDouble(map, key);
        if (d == null) {
            return defaultValue;
        }
        return d;
    }


    public static Long getLong(Map<String, Object> map, String key) {
        if (map == null) {
            return null;
        }
        if (!map.containsKey(key)) {
            return null;
        }
        Object value = map.get(key);
        if (value == null) {
            return null;
        }
        return (long) value;
    }

    public static long getLong(Map<String, Object> map, String key, long defaultValue) {
        Long l = getLong(map, key);
        if (l == null) {
            return defaultValue;
        }
        return l;
    }

    public static Boolean getBoolean(Map<String, Object> map, String key) {
        if (map == null) {
            return null;
        }
        if (!map.containsKey(key)) {
            return null;
        }
        Object value = map.get(key);
        if (value == null) {
            return null;
        }
        return (boolean) value;
    }

    public static boolean getBoolean(Map<String, Object> map, String key, boolean defaultValue) {
        Boolean b = getBoolean(map, key);
        if (b == null) {
            return defaultValue;
        }
        return b;
    }
}
