package hr.fer.labust.diverapp.agent;

import com.google.android.gms.maps.model.LatLng;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import hr.fer.labust.diverapp.common.Colors;

public class Agent {
    private String mName;
    private LatLng mPosition = null;
    private LatLng mDestination = null;
    private int mPositionColor = 0;
    private int mDestinationColor = 0;

    List<String> mAttributeGroups;
    Map<String, AttributeList> mAttributes;

    Agent(String name) {
        mName = name;

        mAttributeGroups = new ArrayList<>();
        mAttributes = new HashMap<>();
        mPositionColor = Colors.getColor();
    }

    public void put(String group, String attribute, String value) {
        if (!mAttributes.containsKey(group)) {
            mAttributeGroups.add(group);
            mAttributes.put(group, new AttributeList());
        }

        AttributeList attributes = mAttributes.get(group);
        attributes.put(attribute, value);
    }

    public void setPosition(String latitude, String longitude) {
        mPosition = new LatLng(Double.parseDouble(latitude), Double.parseDouble(longitude));
        put("Position", "latitude", latitude);
        put("Position", "longitude", longitude);
    }

    public void setDestination(String latitude, String longitude) {
        if (mDestination == null) {
            mDestinationColor = Colors.getColor();
        }

        mDestination = new LatLng(Double.parseDouble(latitude), Double.parseDouble(longitude));
        put("Destination", "latitude", latitude);
        put("Destination", "longitude", longitude);
    }

    public String getName() {
        return mName;
    }

    public int getColor() {
        return mPositionColor;
    }

    public int getDestinationColor() {
        return mDestinationColor;
    }

    public LatLng getPosition() {
        return mPosition;
    }

    public LatLng getDestination() {
        return mDestination;
    }

    public Attribute getStatus(int groupIndex, int statusIndex) {
        return mAttributes.get(mAttributeGroups.get(groupIndex)).get(statusIndex);
    }

    public int getNumberOfStatsInGroup(int groupIndex) {
        return mAttributes.get(mAttributeGroups.get(groupIndex)).size();
    }

    public String getGroupName(int index) {
        return mAttributeGroups.get(index);
    }

    public int getNumberOfGroupStats() {
        return mAttributeGroups.size();
    }
}
