package rasel.lunar.launcher.model

import io.realm.kotlin.ext.realmListOf
import io.realm.kotlin.types.RealmList
import io.realm.kotlin.types.RealmObject
import io.realm.kotlin.types.annotations.Ignore


class WeatherForcast: RealmObject {
    var location: Location? = null
    var current: Current? = null
    var forecast: Forecast? = null

    fun readyForSaving() {
        forecast?.fill()
    }
}

//////////////////////////////////
class Location: RealmObject {
    var name: String? = null
    var region: String? = null
    var country: String? = null
    var lat = 0.0
    var lon = 0.0
    var tz_id: String? = null
    var localtime_epoch = 0
    var localtime: String? = null
}

class Current: RealmObject {
    var last_updated_epoch = 0
    var last_updated: String? = null
    var temp_c = 0.0
    var temp_f = 0.0
    var is_day = 0
    var condition: Condition? = null
    var wind_mph = 0.0
    var wind_kph = 0.0
    var wind_degree = 0
    var wind_dir: String? = null
    var pressure_mb = 0.0
    var pressure_in = 0.0
    var precip_mm = 0.0
    var precip_in = 0.0
    var humidity = 0
    var cloud = 0
    var feelslike_c = 0.0
    var feelslike_f = 0.0
    var windchill_c = 0.0
    var windchill_f = 0.0
    var heatindex_c = 0.0
    var heatindex_f = 0.0
    var dewpoint_c = 0.0
    var dewpoint_f = 0.0
    var vis_km = 0.0
    var vis_miles = 0.0
    var uv = 0.0
    var gust_mph = 0.0
    var gust_kph = 0.0
}

class Forecast: RealmObject {
    @Ignore
    var forecastday: ArrayList<Forecastday> = arrayListOf()
    var forecastdayRealm: RealmList<Forecastday> = realmListOf()

    fun fill() {
        if (forecastdayRealm.addAll(forecastday)) {
            forecastdayRealm.forEach { f -> f.fill() }
        }
    }
}

//////////////////////////////////
// Current
class Condition: RealmObject {
    var text: String? = null
    var icon: String? = null
    var code = 0
}
// Forecast
class Forecastday: RealmObject {
    var date: String? = null
    var date_epoch = 0
    var day: Day? = null
    var astro: Astro? = null
    @Ignore
    var hour: ArrayList<Hour> = arrayListOf()
    var hourRealm: RealmList<Hour> = realmListOf()

    fun fill() {
        hourRealm.addAll(hour)
    }
}

//////////////////////////////////
// Forecastday
class Day: RealmObject {
    var maxtemp_c = 0.0
    var maxtemp_f = 0.0
    var mintemp_c = 0.0
    var mintemp_f = 0.0
    var avgtemp_c = 0.0
    var avgtemp_f = 0.0
    var maxwind_mph = 0.0
    var maxwind_kph = 0.0
    var totalprecip_mm = 0.0
    var totalprecip_in = 0.0
    var totalsnow_cm = 0.0
    var avgvis_km = 0.0
    var avgvis_miles = 0.0
    var avghumidity = 0
    var daily_will_it_rain = 0
    var daily_chance_of_rain = 0
    var daily_will_it_snow = 0
    var daily_chance_of_snow = 0
    var condition: Condition? = null
    var uv = 0.0
}

class Astro: RealmObject {
    var sunrise: String? = null
    var sunset: String? = null
    var moonrise: String? = null
    var moonset: String? = null
    var moon_phase: String? = null
    var moon_illumination = 0
    var is_moon_up = 0
    var is_sun_up = 0
}

class Hour: RealmObject {
    var time_epoch = 0
    var time: String? = null
    var temp_c = 0.0
    var temp_f = 0.0
    var is_day = 0
    var condition: Condition? = null
    var wind_mph = 0.0
    var wind_kph = 0.0
    var wind_degree = 0
    var wind_dir: String? = null
    var pressure_mb = 0.0
    var pressure_in = 0.0
    var precip_mm = 0.0
    var precip_in = 0.0
    var snow_cm = 0.0
    var humidity = 0
    var cloud = 0
    var feelslike_c = 0.0
    var feelslike_f = 0.0
    var windchill_c = 0.0
    var windchill_f = 0.0
    var heatindex_c = 0.0
    var heatindex_f = 0.0
    var dewpoint_c = 0.0
    var dewpoint_f = 0.0
    var will_it_rain = 0
    var chance_of_rain = 0
    var will_it_snow = 0
    var chance_of_snow = 0
    var vis_km = 0.0
    var vis_miles = 0.0
    var gust_mph = 0.0
    var gust_kph = 0.0
    var uv = 0.0
}