package com.bc_chat.contacts.dataSource

import com.bc_chat.bc_base.entity.dao.GroupMemberDao
import com.bc_chat.bc_base.entity.group.Group
import com.bc_chat.bc_base.http.Encryption
import com.bc_chat.bc_base.http.RetrofitHelper
import com.zhaohaoting.framework.abs.datasource.RxDataSource
import com.zhaohaoting.framework.abs.entity.ResultEntity
import com.zhaohaoting.framework.requset.rxjava_retrofit.RxResultSubscriber
import io.reactivex.Flowable
import io.reactivex.schedulers.Schedulers
import java.util.*

/**
 * author：Created by zhaohaoting on 2019/2/27
 * email：526309416@qq.com
 * desc：群列表
 */
class GroupDataSource : RxDataSource<Group, List<Group>>() {

    override fun loadListFromNetWork(params: HashMap<String, Any?>): Flowable<ResultEntity<List<Group>>>? {
        return RetrofitHelper.api.getGroupList(Encryption.encryption(params)).doOnNext {
            if (it.error == RxResultSubscriber.REQUEST_SUCCESS) {
                Schedulers.newThread().createWorker().schedule {
                    GroupMemberDao.instance.syncGroupInfo(it.data)
                }
            }
        }
    }

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