package com.bc_chat.im.activity.envelopes;

import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bc_chat.bc_base.config.RouteConfig;
import com.bc_chat.bc_base.contract.WalletContract;
import com.bc_chat.bc_base.entity.wallet.WalletEntity;
import com.bc_chat.bc_base.presenter.WalletPresenter;
import com.bc_chat.im.R;
import com.zhaohaoting.framework.abs.BaseActivity;
import com.zhaohaoting.framework.utils.ToastUtils;

import org.jetbrains.annotations.Nullable;

/**
 * 我的钱包
 */
@Route(path = RouteConfig.MY_WALLET_ACTIVITY)
public class MyWalletActivity extends BaseActivity<WalletPresenter> implements WalletContract.View {

    private TextView tvAmount;

    @Override
    protected WalletPresenter initPresenter() {
        return new WalletPresenter<>(this);
    }

    @Override
    public int getLayoutResId() {
        return R.layout.activity_my_wallet;
    }

    @Override
    protected void initialize() {
        initView();
        initListener();
    }

    private void initListener() {
        getPresenter().getAccountMoney();
        findViewById(R.id.tvRedPacketRecord).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ARouter.getInstance().build(RouteConfig.REDPACKET_RECORD_ACTIVITY).navigation();
            }
        });
    }

    private void initView() {
        tvAmount = findViewById(R.id.tvAmount);
    }

    @Override
    public void getAccountMoneySuccess(@Nullable WalletEntity walletEntity) {
        if (walletEntity != null)
            tvAmount.setText("￥ " + walletEntity.getMoney());
    }

    @Override
    public void getAccountMoneyFailure(@Nullable Exception exception) {
        if (exception != null)
            ToastUtils.show(exception.getMessage());
    }
}
