/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package facade;

import java.util.AbstractMap;
import java.util.Map;
import java.util.concurrent.Callable;
import org.json.JSONObject;

/**
 *
 * @author install1
 */
public class CallableJsonObject implements Callable<Map.Entry<String, String>> {

    private JSONObject jsonObject;
    private String avatar;
    private String steamID;

    public CallableJsonObject(JSONObject jsonObject) {
        String steamID64 = jsonObject.getString("steamid");
        this.avatar = jsonObject.getString("avatarfull");
        this.steamID = convertCommunityIdToSteamId(Long.valueOf(steamID64));
    }

    public CallableJsonObject() {
    }

    @Override
    public Map.Entry<String, String> call() throws Exception {
        Map.Entry<String, String> entry = new AbstractMap.SimpleEntry<String, String>(steamID, avatar);
        return entry;
    }

    private String convertCommunityIdToSteamId(long communityId) {
        long steamId1 = communityId % 2;
        long steamId2 = communityId - 76561197960265728L;
        steamId2 = (steamId2 - steamId1) / 2;
        return "STEAM_0:" + steamId1 + ":" + steamId2;
    }

}
