package com.bc_chat.bc_base.task

import com.bc_chat.bc_base.entity.User
import com.bc_chat.bc_base.entity.dao.GroupMemberDao
import com.bc_chat.bc_base.http.Encryption
import com.bc_chat.bc_base.http.RetrofitHelper
import com.zhaohaoting.framework.abs.entity.ResultEntity
import com.zhaohaoting.framework.abs.task.RxDataAsyncTask
import com.zhaohaoting.framework.requset.rxjava_retrofit.RxResultSubscriber
import io.reactivex.Flowable
import io.reactivex.schedulers.Schedulers

/**
 * author：Created by zhaohaoting on 2019/3/5
 * email：526309416@qq.com
 * desc：获取用户信息
 */
class UserInfoTask constructor(var cuid: String) : RxDataAsyncTask<User, ResultEntity<User>>() {
    //cuid	int	是	被获取资料用户id
    override fun loadDataAsyncTask(): Flowable<ResultEntity<User>>? {
        val params: MutableMap<String, Any?> = mutableMapOf("cuid" to cuid)
        return RetrofitHelper.api.getUserInfo(Encryption.encryption(params)).doOnNext {
            if (it.error == RxResultSubscriber.REQUEST_SUCCESS) {
                Schedulers.newThread().createWorker().schedule {
                    GroupMemberDao.instance.saveMemberInfo(cuid, it.data)
                }
            }
        }
    }
}
