package net.heartshield.data;

import com.google.gson.annotations.SerializedName;

import net.heartshield.util.JsonUtil;

/**
 * Meta-data about the app, such as its unique ID and install date.
 * App ID assignments are privacy relevant.
 *
 * @author David Madl (git@abanbytes.eu)
 * @date 2017-04-07
 */
public class AppMeta {
    public String version;
    public String codename;

    /** client git hash */
    @SerializedName("git_hash")
    public String gitHash;

    /** client build type - debug or release? */
    @SerializedName("build_type")
    public String buildType;

    /** exact version code of Android package */
    @SerializedName("version_code")
    public String versionCode;

    /**
     * UTC unix timestamp in seconds
     */
    @SerializedName("install_date")
    public long installDate;

    @SerializedName("install_android_versions")
    public AndroidMeta installAndroidVersions;

    @SerializedName("id")
    public String appId;

    /**
     * UTC unix timestamp in seconds
     */
    @SerializedName("first_install_date")
    public long firstInstallDate;

    public String serialize() {
        return JsonUtil.getGson().toJson(this);
    }

    public static AppMeta deserialize(String json) {
        return JsonUtil.getGson().fromJson(json, AppMeta.class);
    }

    public static class AndroidMeta {
        @SerializedName("os.version")
        public String osVersion;
        @SerializedName("Build.VERSION.INCREMENTAL")
        public String buildVersionIncremental;
        @SerializedName("Build.VERSION.SDK_INT")
        public String buildVersionSdkInt;
        @SerializedName("Build.DEVICE")
        public String buildDevice;
        @SerializedName("Build.MODEL")
        public String buildModel;
        @SerializedName("Build.PRODUCT")
        public String buildProduct;
    }
}
