package com.koeping.lukas.sensordatacollector;

import android.os.Environment;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Calendar;


public class Helper
{

    /* Checks if external storage is available for read and write */
    public static boolean isExternalStorageWritable() {
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            return true;
        }
        return false;
    }

    public static String getCurretDate() {
        String currentDate =
                Calendar.getInstance().get(Calendar.YEAR) + "_" +
                        (Calendar.getInstance().get(Calendar.MONTH)+1) + "_" +
                        Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + "_" +
                        Calendar.getInstance().get(Calendar.HOUR_OF_DAY) + "_" +
                        Calendar.getInstance().get(Calendar.MINUTE) + "_" +
                        Calendar.getInstance().get(Calendar.SECOND);

        return currentDate;
    }

    public static File getStorageRoot() throws FileNotFoundException{
        File root;
        if(Helper.isExternalStorageWritable()) {
            root = Environment.getExternalStorageDirectory();
        } else {
            throw new FileNotFoundException("External storage not writeable");
        }

        return root;
    }

    private class EventInformation {
        private int event_id;
        private long timestamp;
        private boolean start;

        EventInformation(int event_id, long timestamp, boolean start) {
            this.event_id = event_id;
            this.timestamp = timestamp;
            this.start = start;
        }

        public int getEvent_id() {
            return event_id;
        }

        public long getTimestamp() {
            return timestamp;
        }

        public boolean isStart() {
            return start;
        }
    }


}
