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 Response<D>(
        private val status: Int = 0,
        private val message: String? = null,
        private val total: Int = 0,
        private val count: Int = 10,
        private val datas: D? = null
) : IResponse<D> {

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

        if (showError && !ok) {
            Toasts.toast(BApp.instance(), msg())
        }
        return ok
    }

    override fun code(): Int {
        return status
    }

    override fun count(): Int {
        return count
    }

    override fun total(): Int {
        return total
    }

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

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

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

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