package com.bc_chat.bc_base.task

import com.bc_chat.bc_base.entity.ListModel
import com.bc_chat.bc_base.entity.group.MemberBean
import com.bc_chat.bc_base.http.Encryption
import com.bc_chat.bc_base.http.RetrofitHelper
import com.bc_chat.bc_base.utils.Const
import com.zhaohaoting.framework.abs.datasource.RxDataSource
import com.zhaohaoting.framework.abs.entity.ResultEntity
import io.reactivex.Flowable
import java.util.*

/**
 * author：Created by zhaohaoting on 2019/2/27
 * email：526309416@qq.com
 * desc：群管理
 */
class GroupFilterDataSource constructor(var groupId: String, var type: Int? = 0) : RxDataSource<MemberBean, ListModel<MemberBean>>() {
    //1 管理员  2 非管理员
    override fun loadListFromNetWork(params: HashMap<String, Any>): Flowable<ResultEntity<ListModel<MemberBean>>>? {
        val params: MutableMap<String, Any?> = mutableMapOf("groupId" to groupId)
        return RetrofitHelper.api.queryGroupMember(Encryption.encryption(params)).map {
            if (type == 1) {
                val list = it.data.list
                val filter = list.filter {
                    Const.GROUP_ROLE.ROLE_GROUP_ORDINARY != it.type
                }
                list.clear()
                list.addAll(filter)
            } else if (type == 2) {
                val list = it.data.list
                val filter = list.filter {
                    Const.GROUP_ROLE.ROLE_GROUP_ORDINARY == it.type
                }
                list.clear()
                list.addAll(filter)
            }

            return@map it
        }
    }

    override fun hasMore(): Boolean {
        return false
    }
}
