package com.quansu.heifengwuliu.utils.net

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

class BBDCResponse<D>(
        private val code: Int = 1,
        private val msg: String? = null,
        private val total: Int = 0,
        private val count: Int = 10,
        private val wordlist: D? = null
) : IResponse<D> {

    override fun ok(showError: Boolean): Boolean {
        val ok = code == 1

        if (showError && !ok) {
            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 wordlist
    }

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

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