package com.aaron.kakao.hospitalmapfortube.ui.main

import android.location.Location
import android.util.Log
import com.aaron.kakao.hospitalmapfortube.core.BaseViewModel
import com.aaron.kakao.hospitalmapfortube.data.remote.api.MapAPI
import com.aaron.kakao.hospitalmapfortube.data.remote.model.Category
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import net.daum.mf.map.api.MapPoint
import net.daum.mf.map.api.MapReverseGeoCoder

/**
 * Created by aaron on 2020-03-26
 */

class MainViewModel(private val api: MapAPI) : BaseViewModel() {
    lateinit var doMapReverseGeoCoder: (Category) -> Unit

    fun getCategory(location: Location?) {
        val parameter = mutableMapOf(
            "category_group_code" to "HP8",
            "radius" to "500",
            "x" to "${location!!.latitude}",
            "y" to "${location.longitude}",
            "sort" to "distance"
        )
        addToDisposable(api.getCategory(parameter)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe({category ->
               if (category != null) {
                   Log.d("aaron", category.toString())
                   doMapReverseGeoCoder(category)
               }
            },{})
        )
    }
}