package com.casic.br.view

import com.casic.br.R
import com.casic.br.adapter.FaultDescAdapter
import com.casic.br.adapter.FaultDescAdapter2
import com.casic.br.model.SolutionModel
import com.casic.br.model.SolutionModel2
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.gyf.immersionbar.ImmersionBar
import com.pengxh.kt.lite.base.KotlinBaseActivity
import com.pengxh.kt.lite.extensions.convertColor
import com.pengxh.kt.lite.extensions.readAssetsFile
import com.pengxh.kt.lite.utils.Constant
import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil
import kotlinx.android.synthetic.main.activity_fault_description.*
import kotlinx.android.synthetic.main.include_base_title.*

class FaultDescriptionActivity : KotlinBaseActivity() {

    private val gson by lazy { Gson() }

    override fun initLayoutView(): Int = R.layout.activity_fault_description

    override fun observeRequestState() {

    }

    override fun setupTopBarLayout() {
        ImmersionBar.with(this).statusBarDarkFont(true).init()
        ImmerseStatusBarUtil.setColor(this, R.color.white.convertColor(this))

        leftBackView.setOnClickListener { finish() }
        titleView.text = "故障说明"
    }

    override fun initData() {
        when (intent.getStringExtra(Constant.INTENT_PARAM)!!) {
            "燃气灶" -> {
                val assetsContent = readAssetsFile("cooker_fault_desc.json")
                val descModels = gson.fromJson<MutableList<SolutionModel2>>(
                    assetsContent, object : TypeToken<MutableList<SolutionModel2>>() {}.type
                )
                faultDescriptionView.adapter = FaultDescAdapter2(this, descModels)
            }
            "壁挂炉" -> {
                val assetsContent = readAssetsFile("fireplace_fault_desc.json")
                val descModels = gson.fromJson<MutableList<SolutionModel>>(
                    assetsContent, object : TypeToken<MutableList<SolutionModel>>() {}.type
                )
                faultDescriptionView.adapter = FaultDescAdapter(this, descModels)
            }
            "热水器" -> {
                val assetsContent = readAssetsFile("waterheater_fault_desc.json")
                val descModels = gson.fromJson<MutableList<SolutionModel>>(
                    assetsContent, object : TypeToken<MutableList<SolutionModel>>() {}.type
                )
                faultDescriptionView.adapter = FaultDescAdapter(this, descModels)
            }
        }
    }

    override fun initEvent() {

    }
}