package com.doverfuelingsolutions.issp.api.dto

import androidx.annotation.StringRes
import com.doverfuelingsolutions.issp.R
import com.doverfuelingsolutions.issp.utils.StringUtil

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> fail(msg: String): DFSResult<T> {
            return DFSResult(false, null, when {
                msg.contains("No address associated with hostname", true) -> StringUtil.get(R.string.network_error_host_error)
                else -> msg
            })
        }

        fun <T> fail(@StringRes id: Int): DFSResult<T> = fail(StringUtil.get(id))

        fun <T> fail(obj: T, @StringRes id: Int): DFSResult<T> {
            return DFSResult(false, obj, StringUtil.get(id))
        }
    }
}