import android.util.Log
import com.apps.sketchmaster.data.Base
import com.apps.sketchmaster.data.BaseDao
import com.apps.sketchmaster.data.Customize
import com.apps.sketchmaster.data.CustomizeDao


class EntityRepository(private val baseDao: BaseDao, private val customizeDao: CustomizeDao) {
    //----------base
    suspend fun insertBase(base: Base) {
        try {
            baseDao.insert(base)
        } catch (e: Exception) {
            Log.d("Repository","insert data error$e")
        }
    }

    suspend fun getAllBases(): List<Base> {
        return baseDao.getAll()
    }

    suspend fun getBaseByPath(path: String): Base? {
        return baseDao.selectByPath(path)
    }

    suspend fun deleteBaseByPath(path: String): Boolean {
        return try {
            baseDao.deleteByPath(path)
            true
        } catch (e: Exception) {
            Log.d("Repository","delete data error$e")
            false
        }
    }

    //---------customize

    suspend fun insertCustomize(customize: Customize) {
        try {
            customizeDao.insert(customize)
        } catch (e: Exception) {
            Log.d("Repository","insert data error$e")
        }
    }

    suspend fun getAllCustomizes(): List<Customize> {
        return customizeDao.getAll()
    }

    suspend fun getCustomizeByPath(path: String): Customize? {
        return customizeDao.selectByPath(path)
    }

    suspend fun deleteCustomizeByPath(path: String): Boolean {
        return try {
            customizeDao.deleteByPath(path)
            true
        } catch (e: Exception) {
            false
        }
    }
}