package de.apps4ics.mountainnavigation;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by Vinz on 06.03.2016.
 */
public class WeatherDatabase extends SQLiteOpenHelper {
    private static final int DATABASE_VERSION = 1;
    private static final String DATABASE_NAME = "weathers.db";
    private static final String TABLE_WEATHER = "weather";
    private static final String TABLE_LOCATION = "locations";
    private static final String TABLE_WIND = "winds";

    private static final String KEY_ID = "_id";
    private static final String KEY_TIMESTAMP = "_timestamp";
    private static final String KEY_TEMP_MIN = "_temp_min";
    private static final String KEY_TEMP_MAX = "_temp_max";
    private static final String KEY_LOCATION_ID = "_loc_id";
    private static final String KEY_SUNRISE = "_sunrise";
    private static final String KEY_SUNSET = "_sunset";
    private static final String KEY_WEATHER_ID = "_weather_id";
    private static final String KEY_WEATHER_CODE = "_weather_code";
    private static final String KEY_PRESSURE = "_pressure";
    private static final String KEY_HUMIDITY = "_humidity";
    private static final String KEY_MAIN = "_main";
    private static final String KEY_DESC = "_desc";
    private static final String KEY_WIND_ID = "_wind_id";
    private static final String KEY_RAIN = "_rain"; //Rain volume for the last 3 hours
    private static final String KEY_SNOW = "_snow"; //Snow volume for the last 3 hours
    private static final String KEY_CLOUDS = "_clouds"; //cloudiness in %

    private static final String KEY_LAT = "_lat";
    private static final String KEY_LON = "_lon";
    private static final String KEY_ALT = "_alt";
    private static final String KEY_NAME = "_name";
    private static final String KEY_COUNTRY = "_country";

    private static final String KEY_SPEED = "_speed";
    private static final String KEY_DIR = "_dir";

    public WeatherDatabase(Context context){
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String CREATE_WEATHER_TABLE = "CREATE TABLE " + TABLE_WEATHER + "("
                + KEY_ID + " INTEGER PRIMARY KEY,"
                +  KEY_TIMESTAMP + " INTEGER,"
                +  KEY_TEMP_MIN + " REAL,"
                +  KEY_TEMP_MAX + " REAL,"
                +  KEY_LOCATION_ID + " INTEGER,"
                +  KEY_SUNRISE + " INTEGER,"
                +  KEY_SUNSET + " INTEGER,"
                +  KEY_WEATHER_ID + " INTEGER,"
                +  KEY_WEATHER_CODE + " INTEGER,"
                +  KEY_PRESSURE + " REAL,"
                +  KEY_HUMIDITY + " REAL,"
                +  KEY_MAIN + " TEXT,"
                +  KEY_DESC + " TEXT,"
                +  KEY_WIND_ID + " INTEGER,"
                +  KEY_RAIN + " REAL,"
                +  KEY_SNOW + " REAL,"
                +  KEY_CLOUDS + " INTEGER" + ")";
        db.execSQL(CREATE_WEATHER_TABLE);
        String CREATE_LOCATION_TABLE = "CREATE TABLE " + TABLE_LOCATION + "("
                + KEY_ID + " INTEGER PRIMARY KEY,"
                + KEY_LAT + " REAL,"
                + KEY_LON + " REAL,"
                + KEY_ALT + " REAL,"
                + KEY_NAME + " TEXT,"
                + KEY_COUNTRY + " TEXT" + ")";
        db.execSQL(CREATE_LOCATION_TABLE);
        String CREATE_WIND_TABLE = "CREATE TABLE " + TABLE_WIND + "("
                + KEY_ID + " INTEGER PRIMARY KEY,"
                + KEY_SPEED + " REAL,"
                + KEY_DIR + " REAL" + ")";
        db.execSQL(CREATE_WIND_TABLE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        //TODO?
    }

    public int insertWeather(MyWeather weather) {
        return 0;
    }
}
