// Path: GreeRemoteAndroid/app/src/main/java/tomikaa/greeremote/Gree/Deserializers/PackDeserializer.java
// public class PackDeserializer implements JsonDeserializer<Pack> {
// 
//     @Override
//     public Pack deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
//         JsonObject jsonObject = jsonElement.getAsJsonObject();
// 
//         String packType = jsonObject.get("t").getAsString();
// 
//         if (packType.equalsIgnoreCase(BindOkPack.TYPE)) {
//             return jsonDeserializationContext.deserialize(jsonObject, BindOkPack.class);
//         } else if (packType.equalsIgnoreCase(BindPack.TYPE)) {
//             return jsonDeserializationContext.deserialize(jsonObject, BindPack.class);
//         } else if (packType.equalsIgnoreCase(DatPack.TYPE)) {
//             return jsonDeserializationContext.deserialize(jsonObject, DatPack.class);
//         } else if (packType.equalsIgnoreCase(ResultPack.TYPE)) {
//             return jsonDeserializationContext.deserialize(jsonObject, ResultPack.class);
//         } else if (packType.equalsIgnoreCase(StatusPack.TYPE)) {
//             return jsonDeserializationContext.deserialize(jsonObject, StatusPack.class);
//         } else if (packType.equalsIgnoreCase(DevicePack.TYPE)) {
//             return jsonDeserializationContext.deserialize(jsonObject, DevicePack.class);
//         }
// 
//         return null;
//     }
// }
// 
// Path: GreeRemoteAndroid/app/src/main/java/tomikaa/greeremote/Gree/Network/DeviceKeyChain.java
// public class DeviceKeyChain {
//     private final HashMap<String, String> mKeys = new HashMap<>();
// 
//     public void addKey(String deviceId, String key) {
//         mKeys.put(deviceId.toLowerCase(), key);
//     }
// 
//     public String getKey(String deviceId) {
//         if (deviceId == null)
//             return null;
// 
//         String id = deviceId.toLowerCase();
// 
//         if (!mKeys.containsKey(id))
//             return null;
// 
//         return mKeys.get(id);
//     }
// 
//     public boolean containsKey(String deviceId) {
//         if (deviceId == null)
//             return false;
//         
//         return mKeys.containsKey(deviceId.toLowerCase());
//     }
// }
// 
// Path: GreeRemoteAndroid/app/src/main/java/tomikaa/greeremote/Gree/Packets/Packet.java
// public class Packet {
//     @SerializedName("t")
//     public String type;
// 
//     public String tcid;
//     public Integer i;
//     public Integer uid;
//     public String cid;
// 
//     @SerializedName("pack")
//     public String encryptedPack;
// 
//     public transient Pack pack;
// }
// 
// Path: GreeRemoteAndroid/app/src/main/java/tomikaa/greeremote/Gree/Packs/DatPack.java
// public class DatPack extends Pack {
//     public static String TYPE = "dat";
// 
//     @SerializedName("r")
//     public int resultCode;
// 
//     @SerializedName("cols")
//     public String[] keys;
// 
//     @SerializedName("dat")
//     public Integer[] values;
// 
//     public DatPack() {
//         type = TYPE;
//     }
// }
// 
// Path: GreeRemoteAndroid/app/src/main/java/tomikaa/greeremote/Gree/Packs/Pack.java
// public class Pack {
//     @SerializedName("t")
//     public String type;
// 
//     public String mac;
// }


import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.HashMap;
import java.util.Map;
import tomikaa.greeremote.Gree.Deserializers.PackDeserializer;
import tomikaa.greeremote.Gree.Network.DeviceKeyChain;
import tomikaa.greeremote.Gree.Packets.Packet;
import tomikaa.greeremote.Gree.Packs.DatPack;
import tomikaa.greeremote.Gree.Packs.Pack;
package tomikaa.greeremote.Gree;





/*
 * This file is part of GreeRemoteAndroid.
 *
 * GreeRemoteAndroid is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * GreeRemoteAndroid is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GreeRemoteAndroid. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Created by tomikaa87 <https://github.com/tomikaa87> on 2017-11-26.
 */

public class Utils {

    public static class Unzipped {
        public final String[] keys;
        public final Integer[] values;

        public Unzipped(String[] keys, Integer[] values) {
            this.keys = keys;
            this.values = values;
        }
    }

    public static Map<String, Integer> zip(String[] keys, Integer[] values) throws IllegalArgumentException {
        if (keys.length != values.length)
            throw new IllegalArgumentException("Length of keys and values must match");

        Map<String, Integer> zipped = new HashMap<>();
        for (int i = 0; i < keys.length; i++) {
            zipped.put(keys[i], values[i]);
        }

        return zipped;
    }

    public static Unzipped unzip(Map<String, Integer> map) {
        return new Unzipped(map.keySet().toArray(new String[0]), map.values().toArray(new Integer[0]));
    }

    public static Map<String, Integer> getValues(DatPack pack) {
        return zip(pack.keys, pack.values);
    }

    public static String serializePacket(Packet packet, DeviceKeyChain deviceKeyChain) {
// Path: GreeRemoteAndroid/app/src/main/java/tomikaa/greeremote/Gree/Deserializers/PackDeserializer.java
// public class PackDeserializer implements JsonDeserializer<Pack> {
// 
//     @Override
//     public Pack deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
//         JsonObject jsonObject = jsonElement.getAsJsonObject();
// 
//         String packType = jsonObject.get("t").getAsString();
// 
//         if (packType.equalsIgnoreCase(BindOkPack.TYPE)) {
//             return jsonDeserializationContext.deserialize(jsonObject, BindOkPack.class);
//         } else if (packType.equalsIgnoreCase(BindPack.TYPE)) {
//             return jsonDeserializationContext.deserialize(jsonObject, BindPack.class);
//         } else if (packType.equalsIgnoreCase(DatPack.TYPE)) {
//             return jsonDeserializationContext.deserialize(jsonObject, DatPack.class);
//         } else if (packType.equalsIgnoreCase(ResultPack.TYPE)) {
//             return jsonDeserializationContext.deserialize(jsonObject, ResultPack.class);
//         } else if (packType.equalsIgnoreCase(StatusPack.TYPE)) {
//             return jsonDeserializationContext.deserialize(jsonObject, StatusPack.class);
//         } else if (packType.equalsIgnoreCase(DevicePack.TYPE)) {
//             return jsonDeserializationContext.deserialize(jsonObject, DevicePack.class);
//         }
// 
//         return null;
//     }
// }
// 
// Path: GreeRemoteAndroid/app/src/main/java/tomikaa/greeremote/Gree/Network/DeviceKeyChain.java
// public class DeviceKeyChain {
//     private final HashMap<String, String> mKeys = new HashMap<>();
// 
//     public void addKey(String deviceId, String key) {
//         mKeys.put(deviceId.toLowerCase(), key);
//     }
// 
//     public String getKey(String deviceId) {
//         if (deviceId == null)
//             return null;
// 
//         String id = deviceId.toLowerCase();
// 
//         if (!mKeys.containsKey(id))
//             return null;
// 
//         return mKeys.get(id);
//     }
// 
//     public boolean containsKey(String deviceId) {
//         if (deviceId == null)
//             return false;
//         
//         return mKeys.containsKey(deviceId.toLowerCase());
//     }
// }
// 
// Path: GreeRemoteAndroid/app/src/main/java/tomikaa/greeremote/Gree/Packets/Packet.java
// public class Packet {
//     @SerializedName("t")
//     public String type;
// 
//     public String tcid;
//     public Integer i;
//     public Integer uid;
//     public String cid;
// 
//     @SerializedName("pack")
//     public String encryptedPack;
// 
//     public transient Pack pack;
// }
// 
// Path: GreeRemoteAndroid/app/src/main/java/tomikaa/greeremote/Gree/Packs/DatPack.java
// public class DatPack extends Pack {
//     public static String TYPE = "dat";
// 
//     @SerializedName("r")
//     public int resultCode;
// 
//     @SerializedName("cols")
//     public String[] keys;
// 
//     @SerializedName("dat")
//     public Integer[] values;
// 
//     public DatPack() {
//         type = TYPE;
//     }
// }
// 
// Path: GreeRemoteAndroid/app/src/main/java/tomikaa/greeremote/Gree/Packs/Pack.java
// public class Pack {
//     @SerializedName("t")
//     public String type;
// 
//     public String mac;
// }


// Path: GreeRemoteAndroid/app/src/main/java/tomikaa/greeremote/Gree/Utils.java
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.HashMap;
import java.util.Map;
import tomikaa.greeremote.Gree.Deserializers.PackDeserializer;
import tomikaa.greeremote.Gree.Network.DeviceKeyChain;
import tomikaa.greeremote.Gree.Packets.Packet;
import tomikaa.greeremote.Gree.Packs.DatPack;
import tomikaa.greeremote.Gree.Packs.Pack;

package tomikaa.greeremote.Gree;





/*
 * This file is part of GreeRemoteAndroid.
 *
 * GreeRemoteAndroid is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * GreeRemoteAndroid is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GreeRemoteAndroid. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Created by tomikaa87 <https://github.com/tomikaa87> on 2017-11-26.
 */

public class Utils {

    public static class Unzipped {
        public final String[] keys;
        public final Integer[] values;

        public Unzipped(String[] keys, Integer[] values) {
            this.keys = keys;
            this.values = values;
        }
    }

    public static Map<String, Integer> zip(String[] keys, Integer[] values) throws IllegalArgumentException {
        if (keys.length != values.length)
            throw new IllegalArgumentException("Length of keys and values must match");

        Map<String, Integer> zipped = new HashMap<>();
        for (int i = 0; i < keys.length; i++) {
            zipped.put(keys[i], values[i]);
        }

        return zipped;
    }

    public static Unzipped unzip(Map<String, Integer> map) {
        return new Unzipped(map.keySet().toArray(new String[0]), map.values().toArray(new Integer[0]));
    }

    public static Map<String, Integer> getValues(DatPack pack) {
        return zip(pack.keys, pack.values);
    }

    public static String serializePacket(Packet packet, DeviceKeyChain deviceKeyChain) {
        GsonBuilder gsonBuilder = new GsonBuilder();