package info.knacki.prometheusandroidexporter.collector;

import android.content.Context;

import java.util.ArrayDeque;
import java.util.Calendar;
import java.util.Collection;

import info.knacki.prometheusandroidexporter.CollectorType;
import info.knacki.prometheusandroidexporter.CollectorType.CollectorValue;
import info.knacki.prometheusandroidexporter.ICollector;

public class TestCollector implements ICollector {
    private final CollectorType countCollector = new CollectorType("test_counter", "A count that counts", CollectorType.Type.COUNTER);
    private final CollectorType timerCollector = new CollectorType("test_timer", "A clock that counts", CollectorType.Type.COUNTER);
    private final CollectorType startedAtCollector = new CollectorType("test_started", "A clock that counts", CollectorType.Type.COUNTER);
    private final long serviceStart = System.currentTimeMillis();
    private int count =0;

    private CollectorValue ReadCounter() {
        CollectorValue val = countCollector.new CollectorValue();
        val.SetValue(count++);
        return val;
    }

    private CollectorValue ReadTimer() {
        CollectorValue val = timerCollector.new CollectorValue();
        Calendar cal = Calendar.getInstance();
        val.SetValue(cal.get(Calendar.HOUR_OF_DAY) * 100 + cal.get(Calendar.MINUTE));
        return val;
    }

    private CollectorValue ServiceStartedAt() {
        CollectorValue val = startedAtCollector.new CollectorValue();
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(serviceStart);
        val.SetValue(cal.get(Calendar.HOUR_OF_DAY) * 100 + cal.get(Calendar.MINUTE));
        return val;
    }

    @Override
    public Collection<CollectorValue> ReadValues(Context ctx) {
        ArrayDeque<CollectorValue> result = new ArrayDeque<>();
        result.add(ReadCounter());
        result.add(ReadTimer());
        result.add(ServiceStartedAt());
        return result;
    }
}
