package com.saki.qq.wtlogin.unpack;

import java.util.HashMap;
import java.util.Iterator;

import com.saki.encode.UnPack;
import com.saki.qq.wtlogin.pack.jce.MemberList;
import com.saki.qq.wtlogin.pack.jce.RequestPacket;
import com.saki.qq.wtlogin.pack.jce.TroopList;

import com.saki.qq.taf.jce.JceInputStream;

public class ReFriendList {

    public static class GetFriendGroupList extends RecviePack {
        public GetFriendGroupList(byte[] data) {
            super(data);
        }

    }

    public static class GetTroopListReqV2 extends RecviePack {

        public TroopList list = new TroopList();

        public GetTroopListReqV2(byte[] data) {
            super(data);
            UnPack unpack = new UnPack(data);
            int len = unpack.getInt();
            // System.out.println(len);
            if (len == unpack.length() + 4) {
                JceInputStream in = new JceInputStream(
                        checkZip(unpack.getAll()));
                RequestPacket p = new RequestPacket();
                p.readFrom(in);
                // System.out.println(p);
                in = new JceInputStream(p.sBuffer);
                HashMap<String, byte[]> map = new HashMap<String, byte[]>();
                map.put("", new byte[0]);
                map = (HashMap<String, byte[]>) in.read(map, 0, true);
                Iterator<String> it = map.keySet().iterator();
                while (it.hasNext()) {
                    String key = it.next();
                    byte[] bin = map.get(key);
                    // System.out.println(key + " : " + Canvart.Bytes2Hex(bin));
                    list = (TroopList) new JceInputStream(bin).read(list, 0,
                            true);
                }
            }

        }
    }

    public static class GetTroopMemberList extends RecviePack {
        public MemberList list = new MemberList();

        public GetTroopMemberList(byte[] data) {
            super(data);
            UnPack unpack = new UnPack(data);
            int len = unpack.getInt();
            if (len == unpack.length() + 4) {
                JceInputStream in = new JceInputStream(
                        checkZip(unpack.getAll()));
                RequestPacket p = new RequestPacket();
                p.readFrom(in);
                in = new JceInputStream(p.sBuffer);
                HashMap<String, byte[]> map = new HashMap<String, byte[]>();
                map.put("", new byte[0]);
                map = (HashMap<String, byte[]>) in.read(map, 0, true);
                Iterator<String> it = map.keySet().iterator();
                while (it.hasNext()) {
                    String key = it.next();
                    byte[] bin = map.get(key);
                    // System.out.println(key + " : " + Canvart.Bytes2Hex(bin));
                    list = (MemberList) new JceInputStream(bin).read(list, 0,
                            true);
                }
            }
        }

    }

}
