/*
 * Copyright (C) 2014 Keith Kyzivat
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package info.kkyzivat.ingress_stat_tracker;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map;

import android.content.res.Resources;

public class AgentStats
{
    private Long _id;
    private Date _timestamp;
    private String _agent;
    private long _ap;
    private int _upvs;

    private static final String ISO8601_NOTZ_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public AgentStats()
    {
    }

    public AgentStats(Resources res, Map<String, String> statsMap)
    {
        _timestamp = new Date();
        _agent = statsMap.get(res.getString(R.string.agent_name));
        _ap = Long.parseLong(prepIntegerString(statsMap.get(res.getString(R.string.ap))));
        _upvs = Integer.parseInt(prepIntegerString(statsMap.get(res.getString(R.string.upv))));
    }

    private String prepIntegerString(String str)
    {
        String s = new String(str);
        s = s.replaceAll(",", "");
        int idxNonNum;
        for (idxNonNum = 0; idxNonNum < s.length() && s.substring(idxNonNum, idxNonNum+1).matches("[0-9]"); idxNonNum++);
        s = s.substring(0, idxNonNum);
        return s;
    }

    public Long getId()
    {
        return _id;
    }

    public void setId(long id)
    {
        this._id = Long.valueOf(id);
    }

    public Date getTimestamp()
    {
        return _timestamp;
    }

    public String getIso8601Timestamp()
    {
        SimpleDateFormat sdf = new SimpleDateFormat(ISO8601_NOTZ_FORMAT, Locale.US);
        return sdf.format(_timestamp);
    }

    public void setTimestamp(String iso8601) throws ParseException
    {
        // Locale.US was used to shut up Eclipse.. says for ASCII (which this will be), to use Locale.US..
        // FIXME: Is Locale.US right? (see above)
        SimpleDateFormat sdf = new SimpleDateFormat(ISO8601_NOTZ_FORMAT, Locale.US);
        _timestamp = sdf.parse(iso8601);
    }

    public String getAgent()
    {
        return _agent;
    }

    public void setAgent(String agent)
    {
        this._agent = agent;
    }

    public long getAp()
    {
        return _ap;
    }

    public void setAp(long ap)
    {
        this._ap = ap;
    }

    public int getUpvs()
    {
        return _upvs;
    }

    public void setUpvs(int upvs)
    {
        this._upvs = upvs;
    }
}

@@ -962,16 +962,776 @@
 t _upvs;
+%0A    private int _portalsDiscovered;%0A    private long _xmCollected;%0A    private int _hacks;%0A    private int _resonatorsDeployed;%0A    private int _linksCreated;%0A    private int _controlFieldsCreated;%0A    private int _mindUnitsCaptured;%0A    private int _longestLink;%0A    private int _largestControlField;%0A    private long _xmRecharged;%0A    private int _portalsCaptured;%0A    private int _upcs;%0A    private int _resonatorsDestroyed;%0A    private int _portalsNeutralized;%0A    private int _linksDestroyed;%0A    private int _controlFieldsDestroyed;%0A    private int _distanceWalked;%0A    private int _maxTimePortalHeld;%0A    private int _maxTimeLinkMaintained;%0A    private long _maxLinkLengthxDays;%0A    private int _maxTimeFieldHeld;%0A    private long _largestFieldMuxDays;
 %0A%0A    pr

Add full set of stats to the AgentStats class.