package com.gh.gamecenter.servers.gametest2

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider

class GameServerTestV2ViewModel(application: Application) : AndroidViewModel(application) {

    var tabFilter = TestFilter.RECOMMEND
    val timeFilterList = arrayListOf(RECENT_GAME, TODAY_GAME, FUTURE_GAME)
    val categoryFilterList = arrayListOf("全部类型", "单机游戏", "网络游戏", "福利游戏", "国际服游戏")
    var selectedCategoryFilter: String = categoryFilterList[0]
    var selectedTimeFilterLiveData = MutableLiveData(timeFilterList[1])

    fun getCurrentSelectedCategoryFilterValue(): GameCategory {
        return when (selectedCategoryFilter) {
            "全部类型" -> GameCategory.ALL
            "单机游戏" -> GameCategory.LOCAL
            "网络游戏" -> GameCategory.ONLINE
            "福利游戏" -> GameCategory.WELFARE
            "国际服游戏" -> GameCategory.GJONLINE
            else -> GameCategory.ALL
        }
    }

    fun getSelectedTimeFilterString(dayFilter: String): String {
        return when (dayFilter) {
            TimeFilter.PAST_DAY.value -> RECENT_GAME
            TimeFilter.TODAY.value -> TODAY_GAME
            TimeFilter.UPCOMING_DAY.value -> FUTURE_GAME
            else -> TODAY_GAME
        }
    }

    fun getCurrentSelectedTimeFilter(): String {
        return when (selectedTimeFilterLiveData.value) {
            RECENT_GAME -> TimeFilter.PAST_DAY.value
            TODAY_GAME -> TimeFilter.TODAY.value
            FUTURE_GAME -> TimeFilter.UPCOMING_DAY.value
            else -> TimeFilter.TODAY.value
        }
    }

    fun setSelectedTimeFilter(filter: String?) {
        if (filter.isNullOrEmpty()) return
        selectedTimeFilterLiveData.value = filter
    }

    enum class TestFilter(val value: String) {
        RECOMMEND("recommend"),
        ALL("all"),
    }

    enum class TimeFilter(val value: String) {
        PAST_DAY("recent"),
        TODAY("today"),
        UPCOMING_DAY("future")
    }

    enum class GameCategory(val value: String) {
        ALL("all"),
        LOCAL("local"),
        ONLINE("online"),
        WELFARE("welfare"),
        GJONLINE("gjonline"),
    }

    companion object {
        const val RECENT_GAME = "近期新游"
        const val TODAY_GAME = "今日新游"
        const val FUTURE_GAME = "即将开测"
    }

    class Factory(private val mApplication: Application) :
        ViewModelProvider.NewInstanceFactory() {
        override fun <T : ViewModel> create(modelClass: Class<T>): T {
            return GameServerTestV2ViewModel(mApplication) as T
        }
    }
}