// 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 android.widget.Toast;
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.R;
import org.secuso.privacyfriendlyweather.database.AppDatabase;
    public float getWindSpeed() {
        return windSpeed;
    }

    public void setWindSpeed(float speed) {
        windSpeed = speed;
    }

    /**
     * @return Returns the ID of the record (which uniquely identifies the record).
     */
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    /**
     * @return Returns the date and time for the forecast.
     */
    public long getForecastTime() {
        return forecastTime;
    }

    /**
     * @return Returns the local time for the forecast in UTC epoch
     */
    public long getLocalForecastTime(Context context) {
// 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/Forecast.java
import android.content.Context;
import android.widget.Toast;
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.R;
import org.secuso.privacyfriendlyweather.database.AppDatabase;

    public float getWindSpeed() {
        return windSpeed;
    }

    public void setWindSpeed(float speed) {
        windSpeed = speed;
    }

    /**
     * @return Returns the ID of the record (which uniquely identifies the record).
     */
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    /**
     * @return Returns the date and time for the forecast.
     */
    public long getForecastTime() {
        return forecastTime;
    }

    /**
     * @return Returns the local time for the forecast in UTC epoch
     */
    public long getLocalForecastTime(Context context) {
        AppDatabase dbhelper = AppDatabase.getInstance(context);