package com.genlot.ninglottery.module.function.user;

import android.os.Bundle;

import com.genlot.nativesdk.model.OpBean;
import com.genlot.nativesdk.sender.EventToken;
import com.genlot.nativesdk.sender.TCPSender;
import com.genlot.ninglottery.base.BasePresenter;
import com.genlot.ninglottery.toolkit.LogTool;

import java.util.ArrayList;


/**
 * @author ZhuYongKang
 * @description UserPresent
 * @date 2019/8/5
 */
public class UserPresent extends BasePresenter<IUserView> {

    void queryUsers() {
        getView().showLoading();
        TCPSender.t101043QueryUserList(EventToken.T_QUERY_USER, 1, new TCPSender.SenderCallback() {
            @Override
            public void onSenderSuccess(Bundle bundle) {
                ArrayList<OpBean> list = bundle.getParcelableArrayList(EventToken.EVENT_KEY_RESULT_OBJECT);
                for (OpBean bean : list) {
                    LogTool.logD(bean.toString());
                }
                getView().onSuccess(list);
            }

            @Override
            public void onSenderFail(int code, String message) {
                getView().onFailure(message);
            }
        });
    }

    void addUser(String user) {
        getView().showLoading();
        TCPSender.t101040AddUser(EventToken.T_ADD_USER, 1, Integer.parseInt(user), new TCPSender.SenderCallback() {
            @Override
            public void onSenderSuccess(Bundle bundle) {
                getView().onSuccess("添加成功!");
            }

            @Override
            public void onSenderFail(int code, String message) {
                getView().onFailure(message);
            }
        });
    }

    void delUser(String user) {
        getView().showLoading();
        TCPSender.t101041DelUser(EventToken.T_DEL_USER, 1, Integer.parseInt(user), new TCPSender.SenderCallback() {
            @Override
            public void onSenderSuccess(Bundle bundle) {
                getView().onSuccess("删除成功!");
            }

            @Override
            public void onSenderFail(int code, String message) {
                getView().onFailure(message);
            }
        });
    }

    void changePassword(String userId, String oldPass, String newPass) {
        getView().showLoading();
        TCPSender.t101042ChangeUserPassword(EventToken.T_CHANGE_USER_PASSWORD, 1, Integer.parseInt(userId),
                oldPass, newPass, new TCPSender.SenderCallback() {
                    @Override
                    public void onSenderSuccess(Bundle bundle) {
                        getView().onSuccess(newPass);
                    }

                    @Override
                    public void onSenderFail(int code, String message) {
                        getView().onFailure(message);
                    }
                });
    }

}
