package com.sunny.app.soft.timberkeyboardnew.data

import com.google.gson.Gson
import com.google.gson.JsonArray
import com.google.gson.JsonObject
import com.sunny.app.soft.timberkeyboardnew.App
import com.sunny.app.soft.timberkeyboardnew.data.entity.CategoryEntity
import java.io.InputStream
import java.io.InputStreamReader

class DataManager {

    private fun parseJsonFile(jsonInputStream: InputStream): CategoryEntity {
        val reader = InputStreamReader(jsonInputStream)
        val jsonString = reader.readText()
        val gson = Gson()
        val json = gson.fromJson(jsonString, JsonObject::class.java)
        val entity: CategoryEntity = gson.fromJson(json.toString(), CategoryEntity::class.java)
        return entity
    }

    private fun getCategoryEntity(uil: String): CategoryEntity {
        return parseJsonFile(App.appContext.assets.open(uil))
    }

    fun getModelList(): List<CategoryEntity> {
        val modelList = mutableListOf<CategoryEntity>()
        modelList.add(getCategoryEntity("Abstract.json"))
        modelList.add(getCategoryEntity("Chinese.json"))
        modelList.add(getCategoryEntity("Christmas.json"))
        modelList.add(getCategoryEntity("Glitter.json"))
        modelList.add(getCategoryEntity("Halloween.json"))
        modelList.add(getCategoryEntity("Pastel.json"))
        modelList.add(getCategoryEntity("Unicorn.json"))
        return modelList
    }

}