package com.ys.bdtp.adm.mvvm.model

/**
 * 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
}
