package com.framework.mvvm.model.data

/**
 * ③ UI 数据类
 *
 * 数据最终包装类，无论数据来自本地还是网路；有状态
 *
 * @param state : 数据状态
 * @param  data : 真实数据
 * @param   msg : 提示信息
 */
data class Data<out T>(val state: State, val data: T? = null, val msg: String = "") {
    companion object {
        fun <T> success(data: T?): Data<T> {
            return Data(State.SUCCESS, data, "")
        }

        fun <T> failure(msg: String): Data<T> {
            return Data(State.FAILURE, null, msg)
        }

        fun <T> loading(): Data<T> {
            return Data(State.LOADING, null, "")
        }
    }
}

/**
 * 数据状态
 */
sealed interface State {
    object SUCCESS : State
    object LOADING : State
    object FAILURE : State
}