package info.knacki.prometheusandroidexporter.collector;

import android.content.Context;
import android.os.SystemClock;

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

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

public class DeviceCollector implements ICollector {
    private final CollectorType deviceUptimeCollector = new CollectorType("device_uptime_sec", "Device uptime", CollectorType.Type.COUNTER);
    private final double fAndroidBootTime;

    public DeviceCollector() {
        fAndroidBootTime = (System.currentTimeMillis() - SystemClock.uptimeMillis());
    }

    private CollectorValue Uptime() {
        CollectorValue val = deviceUptimeCollector.new CollectorValue();
        double uptime = System.currentTimeMillis() - fAndroidBootTime;
        val.SetValue((int) Math.round(uptime / 1000.));
        return val;
    }

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