package com.ysnows.base.net

import com.ysnows.base.base.BApp
import com.ysnows.base.utils.Toasts

open class Resp<D>(
        val code: Int = 0,//接口访问失败 1接口访问成功
        val msg: String? = null,
        val total: Int = 0,
        val count: Int = 10,
        val data: D? = null,
        val is_login:Int=0//0 登录超时 1登录成功

) : IResp<D> {

    override fun ok(showError: Boolean): Boolean {

        val ok = code == 1

//        if (showError && !ok) {
//            Toasts.toast(BApp.instance(), msg())
//        }
        if (showError) {//状态成功的时候也可以提示
            Toasts.toast(BApp.instance(), msg())
        }

//        val ok = status == 1
//
////        if (showError && !ok) {
////            Toasts.toast(BApp.instance(), msg())
////        }
//        if (showError) {//状态成功的时候也可以提示
//            Toasts.toast(BApp.instance(), msg())
//        }
        return ok
    }

    override fun code(): Int {
        return code
    }

    override fun count(): Int {
        return count
    }

    override fun total(): Int {
        return total
    }

    override fun msg(): String? {
        return msg
    }

    override fun data(): D? {
        return data
    }

    override fun more(page: Int): Boolean {
        return page * count() < total()
    }

    override fun more(page: Int, pageCount: Int): Boolean {
        return page * count() < total()
    }

    override fun empty(): Boolean {
        return total() <= 0
    }

    override fun isLogin(): Int {
        return isLogin()
    }


}
