/*
 * Copyright 2016 Michael Rozumyanskiy
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.michaelrocks.forecast

import android.app.Application
import com.facebook.drawee.backends.pipeline.Fresco
import io.michaelrocks.forecast.model.ModelModule
import io.michaelrocks.forecast.model.repository.sqlite.CachingForecastRepository
import io.michaelrocks.forecast.model.repository.sqlite.SqliteRepositoryModule
import io.michaelrocks.forecast.model.cities.sqlite.SqliteCitiesModule
import io.michaelrocks.forecast.model.forecast.openweathermap.OpenWeatherMapModule
import io.michaelrocks.forecast.ui.base.DefaultModule
import io.michaelrocks.forecast.ui.base.InjectorHolder
import io.michaelrocks.lightsaber.inject
import rx.android.schedulers.AndroidSchedulers
import javax.inject.Inject

class ForecastApplication : Application() {
  @Inject private val stetho: StethoFacade = inject()

  override fun onCreate() {
    super.onCreate()

    val mainThreadScheduler = AndroidSchedulers.mainThread()
    InjectorHolder.createInjector(
        DefaultModule(this),
        ModelModule(mainThreadScheduler),
        SqliteRepositoryModule(),
        SqliteCitiesModule(),
        OpenWeatherMapModule()
    )
    InjectorHolder.injectMembers(this)

    stetho.initialize(this)
    Fresco.initialize(this)
  }
}
