package com.doverfuelingsolutions.testdemo.api.dto

import androidx.annotation.StringRes

class DFSResult<T> private constructor(
    val success: Boolean = true,
    val data: T?,
    val message: String = "success"
) {

    companion object {

        fun <T> success(obj: T): DFSResult<T> {
            return DFSResult(true, obj, "success")
        }

        fun <T> success(obj: T, msg: String): DFSResult<T> {
            return DFSResult(true, obj, msg)
        }



        fun <T> fail(msg: String): DFSResult<T> {
            return DFSResult(false, null, when {
                msg.contains("No address associated with hostname", true) -> "网络异常或者域名不正确"
                else -> msg
            })
        }
    }
}