import android.util.Log
import com.apps.quicksketchtrace.database.Local
import com.apps.quicksketchtrace.database.LocalDao
import com.apps.quicksketchtrace.database.Upload
import com.apps.quicksketchtrace.database.UploadDao


class DataRepository(private val localDao: LocalDao, private val uploadDao: UploadDao) {
    //----------local
    suspend fun insertLocal(local: Local) {
        try {
            localDao.insert(local)
        } catch (e: Exception) {
            Log.d("Repository","insert data error$e")
        }
    }

    suspend fun getAllLocals(): List<Local> {
        return localDao.getAll()
    }

    suspend fun getLocalByPath(path: String): Local? {
        return localDao.selectByPath(path)
    }

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

    //---------upload

    suspend fun insertUpload(upload: Upload) {
        try {
            uploadDao.insert(upload)
        } catch (e: Exception) {
            Log.d("Repository","insert data error$e")
        }
    }

    suspend fun getAllUploads(): List<Upload> {
        return uploadDao.getAll()
    }

    suspend fun getUploadByPath(path: String): Upload? {
        return uploadDao.selectByPath(path)
    }

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