package com.framework.mvvm.model.data

import android.util.Log

/**
 * 网络数据直接从 from 流入 to
 */
suspend fun <T> toDb(
    from: suspend () -> Model<T>,
    to: suspend (T) -> Unit
): Boolean {
    return when (val response: Response<T> = request { from() }) {
        is EmptyResponse -> {
            false
        }
        is SuccessResponse -> {
            to(response.data)
            true
        }
        is FailureResponse -> {
            Log.d("toDb", response.msg)
            false
        }
    }
}