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.CollectorValue;
import info.knacki.prometheusandroidexporter.ICollector;

public class DeviceCollector implements ICollector {
    private final CollectorValue deviceUptimeCollector = new CollectorValue("device_uptime", "Device uptime (hours)", CollectorValue.Type.COUNTER);
    private final double androidStartHours;

    public DeviceCollector() {
        androidStartHours = (System.currentTimeMillis() - SystemClock.uptimeMillis()) / (1000 * 60 * 60);
    }

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

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