package com.quansu.heifengwuliu.repository

import com.quansu.heifengwuliu.model.User
import com.quansu.heifengwuliu.utils.net.NetEngine
import com.ysnows.base.base.BRepository
import io.reactivex.Observable

open class UserInfoRepository : BRepository() {

    fun getUserInfo(): Observable<User> {
        return Observable.create { emitter ->
            req(NetEngine.service.getUser())
                    .doOnNext() {
                        if (it.ok()) {
                            it.data()?.let { user ->
                                user.save()
                                emitter.onNext(user)
                            }
                        }
                    }
                    .subscribe()
        }
    }


}