// Path: app/src/main/java/org/secuso/privacyfriendlyweather/database/AppDatabase.java
// @Database(entities = {City.class, CityToWatch.class, CurrentWeatherData.class, Forecast.class, WeekForecast.class}, version = AppDatabase.VERSION)
// public abstract class AppDatabase extends RoomDatabase {
//     public static final String DB_NAME = "PF_WEATHER_DB.db";
//     static final int VERSION = 7;
//     static final String TAG = AppDatabase.class.getSimpleName();
// 
//     // DAOs
//     public abstract CityDao cityDao();
//     public abstract CityToWatchDao cityToWatchDao();
//     public abstract CurrentWeatherDao currentWeatherDao();
// 
//     public abstract ForecastDao forecastDao();
// 
//     public abstract WeekForecastDao weekForecastDao();
// 
//     // INSTANCE
//     private static final Object databaseLock = new Object();
//     private static volatile AppDatabase INSTANCE;
// 
//     /**
//      * Get list of all migrations. If they are ContextAwareMigrations, then inject the Context.
//      * @param context to be injected into the ContextAwareMigrations
//      * @return an array of Migrations, this can not be empty
//      */
//     public static Migration[] getMigrations(Context context) {
//         Migration[] MIGRATIONS = new Migration[]{
//                 new Migration_1_2(),
//                 new Migration_2_3(),
//                 new Migration_3_4(),
//                 new Migration_4_5(),
//                 new Migration_5_6(),
//                 new Migration_6_7()
//                 // Add new migrations here
//         };
// 
//         for(Migration m : MIGRATIONS) {
//             if(m instanceof ContextAwareMigration) {
//                 ((ContextAwareMigration) m).injectContext(context);
//             }
//         }
//         return MIGRATIONS;
//     }
// 
//     public static AppDatabase getInstance(Context context) {
//         if(INSTANCE == null) {
//             synchronized (databaseLock) {
//                 if(INSTANCE == null) {
//                     INSTANCE = buildDatabase(context);
//                 }
//             }
//         }
//         return INSTANCE;
//     }
// 
//     private static AppDatabase buildDatabase(final Context context) {
//         Migration[] MIGRATIONS = getMigrations(context);
// 
//         return Room.databaseBuilder(context, AppDatabase.class, DB_NAME)
//                 .addMigrations(MIGRATIONS)
//                 .addCallback(new Callback() {
//                     @Override
//                     public void onCreate(@NonNull SupportSQLiteDatabase db) {
//                         super.onCreate(db);
// 
//                         // disable WAL because of the upcoming big transaction
//                         db.setTransactionSuccessful();
//                         db.endTransaction();
//                         db.disableWriteAheadLogging();
//                         db.beginTransaction();
// 
//                         int cityCount = 0;
//                         Cursor c = db.query("SELECT count(*) FROM CITIES");
//                         if(c != null) {
//                             if(c.moveToFirst()) {
//                                 cityCount = c.getInt(c.getColumnIndex("count(*)"));
//                             }
//                             c.close();
//                         }
// 
//                         Log.d(TAG, "City count: " + cityCount);
//                         if(cityCount == 0) {
//                             fillCityDatabase(context, db);
//                         }
// 
//                         // TODO: DEBUG ONLY - REMOVE WHEN DONE
//                         c = db.query("SELECT count(*) FROM CITIES");
//                         if(c != null) {
//                             if(c.moveToFirst()) {
//                                 cityCount = c.getInt(c.getColumnIndex("count(*)"));
//                             }
//                             c.close();
//                         }
//                         Log.d(TAG, "City count: " + cityCount);
//                     }
//                 })
//                 .allowMainThreadQueries()
//                 .fallbackToDestructiveMigration()
//                 .build();
//     }
// 
//     public static void fillCityDatabase(final Context context, SupportSQLiteDatabase database) {
//         long startInsertTime = System.currentTimeMillis();
// 
//         InputStream inputStream = context.getResources().openRawResource(R.raw.city_list);
//         try {
//             FileReader fileReader = new FileReader();
//             final List<City> cities = fileReader.readCitiesFromFile(inputStream);
// 
//             if (cities.size() > 0) {
//                 for (City c : cities) {
//                     ContentValues values = new ContentValues();
//                     values.put("cities_id", c.getCityId());
//                     values.put("city_name", c.getCityName());
//                     values.put("country_code", c.getCountryCode());
//                     values.put("longitude", c.getLongitude());
//                     values.put("latitude", c.getLatitude());
//                     database.insert("CITIES", SQLiteDatabase.CONFLICT_REPLACE, values);
//                 }
//             }
// 
//             inputStream.close();
//         } catch (IOException e) {
//             e.printStackTrace();
//         }
// 
//         long endInsertTime = System.currentTimeMillis();
//         Log.d("debug_info", "Time for insert:" + (endInsertTime - startInsertTime));
//     }
// }


import android.content.Context;
import androidx.room.ColumnInfo;
import androidx.room.Embedded;
import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Ignore;
import androidx.room.PrimaryKey;
import androidx.room.RoomWarnings;
import org.secuso.privacyfriendlyweather.database.AppDatabase;
    private int weatherID;
    @ColumnInfo(name = "temperature_current")
    private float temperature;
    @ColumnInfo(name = "temperature_min")
    private float temperature_min;
    @ColumnInfo(name = "temperature_max")
    private float temperature_max;
    @ColumnInfo(name = "humidity")
    private float humidity;
    @ColumnInfo(name = "pressure")
    private float pressure;
    @ColumnInfo(name = "precipitation")
    private float precipitation;
    @ColumnInfo(name = "rain_probability")
    private float rain_probability;
    @ColumnInfo(name = "wind_speed")
    private float wind_speed;
    @ColumnInfo(name = "wind_direction")
    private float wind_direction;
    @ColumnInfo(name = "uv_index")
    private float uv_index;
    @Embedded
    private City city;

    public WeekForecast() {
    }

    @Ignore
    public WeekForecast(int id, int city_id, long timestamp, long forecastTime, int weatherID, float temperature, float temperature_min, float temperature_max, float humidity, float pressure, float precipitation, float wind_speed, float wind_direction, float uv_index, float rain_probability) {
        this.id = id;
// Path: app/src/main/java/org/secuso/privacyfriendlyweather/database/AppDatabase.java
// @Database(entities = {City.class, CityToWatch.class, CurrentWeatherData.class, Forecast.class, WeekForecast.class}, version = AppDatabase.VERSION)
// public abstract class AppDatabase extends RoomDatabase {
//     public static final String DB_NAME = "PF_WEATHER_DB.db";
//     static final int VERSION = 7;
//     static final String TAG = AppDatabase.class.getSimpleName();
// 
//     // DAOs
//     public abstract CityDao cityDao();
//     public abstract CityToWatchDao cityToWatchDao();
//     public abstract CurrentWeatherDao currentWeatherDao();
// 
//     public abstract ForecastDao forecastDao();
// 
//     public abstract WeekForecastDao weekForecastDao();
// 
//     // INSTANCE
//     private static final Object databaseLock = new Object();
//     private static volatile AppDatabase INSTANCE;
// 
//     /**
//      * Get list of all migrations. If they are ContextAwareMigrations, then inject the Context.
//      * @param context to be injected into the ContextAwareMigrations
//      * @return an array of Migrations, this can not be empty
//      */
//     public static Migration[] getMigrations(Context context) {
//         Migration[] MIGRATIONS = new Migration[]{
//                 new Migration_1_2(),
//                 new Migration_2_3(),
//                 new Migration_3_4(),
//                 new Migration_4_5(),
//                 new Migration_5_6(),
//                 new Migration_6_7()
//                 // Add new migrations here
//         };
// 
//         for(Migration m : MIGRATIONS) {
//             if(m instanceof ContextAwareMigration) {
//                 ((ContextAwareMigration) m).injectContext(context);
//             }
//         }
//         return MIGRATIONS;
//     }
// 
//     public static AppDatabase getInstance(Context context) {
//         if(INSTANCE == null) {
//             synchronized (databaseLock) {
//                 if(INSTANCE == null) {
//                     INSTANCE = buildDatabase(context);
//                 }
//             }
//         }
//         return INSTANCE;
//     }
// 
//     private static AppDatabase buildDatabase(final Context context) {
//         Migration[] MIGRATIONS = getMigrations(context);
// 
//         return Room.databaseBuilder(context, AppDatabase.class, DB_NAME)
//                 .addMigrations(MIGRATIONS)
//                 .addCallback(new Callback() {
//                     @Override
//                     public void onCreate(@NonNull SupportSQLiteDatabase db) {
//                         super.onCreate(db);
// 
//                         // disable WAL because of the upcoming big transaction
//                         db.setTransactionSuccessful();
//                         db.endTransaction();
//                         db.disableWriteAheadLogging();
//                         db.beginTransaction();
// 
//                         int cityCount = 0;
//                         Cursor c = db.query("SELECT count(*) FROM CITIES");
//                         if(c != null) {
//                             if(c.moveToFirst()) {
//                                 cityCount = c.getInt(c.getColumnIndex("count(*)"));
//                             }
//                             c.close();
//                         }
// 
//                         Log.d(TAG, "City count: " + cityCount);
//                         if(cityCount == 0) {
//                             fillCityDatabase(context, db);
//                         }
// 
//                         // TODO: DEBUG ONLY - REMOVE WHEN DONE
//                         c = db.query("SELECT count(*) FROM CITIES");
//                         if(c != null) {
//                             if(c.moveToFirst()) {
//                                 cityCount = c.getInt(c.getColumnIndex("count(*)"));
//                             }
//                             c.close();
//                         }
//                         Log.d(TAG, "City count: " + cityCount);
//                     }
//                 })
//                 .allowMainThreadQueries()
//                 .fallbackToDestructiveMigration()
//                 .build();
//     }
// 
//     public static void fillCityDatabase(final Context context, SupportSQLiteDatabase database) {
//         long startInsertTime = System.currentTimeMillis();
// 
//         InputStream inputStream = context.getResources().openRawResource(R.raw.city_list);
//         try {
//             FileReader fileReader = new FileReader();
//             final List<City> cities = fileReader.readCitiesFromFile(inputStream);
// 
//             if (cities.size() > 0) {
//                 for (City c : cities) {
//                     ContentValues values = new ContentValues();
//                     values.put("cities_id", c.getCityId());
//                     values.put("city_name", c.getCityName());
//                     values.put("country_code", c.getCountryCode());
//                     values.put("longitude", c.getLongitude());
//                     values.put("latitude", c.getLatitude());
//                     database.insert("CITIES", SQLiteDatabase.CONFLICT_REPLACE, values);
//                 }
//             }
// 
//             inputStream.close();
//         } catch (IOException e) {
//             e.printStackTrace();
//         }
// 
//         long endInsertTime = System.currentTimeMillis();
//         Log.d("debug_info", "Time for insert:" + (endInsertTime - startInsertTime));
//     }
// }


// Path: app/src/main/java/org/secuso/privacyfriendlyweather/database/data/WeekForecast.java
import android.content.Context;
import androidx.room.ColumnInfo;
import androidx.room.Embedded;
import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Ignore;
import androidx.room.PrimaryKey;
import androidx.room.RoomWarnings;
import org.secuso.privacyfriendlyweather.database.AppDatabase;

    private int weatherID;
    @ColumnInfo(name = "temperature_current")
    private float temperature;
    @ColumnInfo(name = "temperature_min")
    private float temperature_min;
    @ColumnInfo(name = "temperature_max")
    private float temperature_max;
    @ColumnInfo(name = "humidity")
    private float humidity;
    @ColumnInfo(name = "pressure")
    private float pressure;
    @ColumnInfo(name = "precipitation")
    private float precipitation;
    @ColumnInfo(name = "rain_probability")
    private float rain_probability;
    @ColumnInfo(name = "wind_speed")
    private float wind_speed;
    @ColumnInfo(name = "wind_direction")
    private float wind_direction;
    @ColumnInfo(name = "uv_index")
    private float uv_index;
    @Embedded
    private City city;

    public WeekForecast() {
    }

    @Ignore
    public WeekForecast(int id, int city_id, long timestamp, long forecastTime, int weatherID, float temperature, float temperature_min, float temperature_max, float humidity, float pressure, float precipitation, float wind_speed, float wind_direction, float uv_index, float rain_probability) {
        this.id = id;
        this.city_id = city_id;