package com.cooleshow.usercenter.presenter

import com.cooleshow.base.constanst.Constanst
import com.cooleshow.base.presenter.BasePresenter
import com.cooleshow.base.rx.BaseObserver
import com.cooleshow.usercenter.bean.UserLoginInfo
import com.cooleshow.usercenter.data.api.UserApi
import com.cooleshow.usercenter.presenter.contract.LoginContract


/*
    登录界面 Presenter
 */
class LoginPresenter constructor() : BasePresenter<LoginContract.LoginView>(),
    LoginContract.Presenter {

    override fun onLoginByPwd(mobile: String?, pwd: String?) {
        view?.showLoading()
        val params = mutableMapOf<String?, String?>()
        params["clientId"] = Constanst.CLIENT
        params["clientSecret"] = Constanst.CLIENT
        params["username"] = mobile
        params["password"] = pwd
        addSubscribe(create(UserApi::class.java).login(params),
            object : BaseObserver<UserLoginInfo>(view) {
                override fun onSuccess(data: UserLoginInfo) {
                    if (view != null) {
                        view.onLoginResult(data)
                    }
                }
            })
    }

}