package top.biduo.exchange.ui.main.presenter;

import top.biduo.exchange.ui.main.MainContract;
import top.biduo.exchange.data.DataSource;
import top.biduo.exchange.entity.Coin;
import top.biduo.exchange.entity.Plate;

/**
 * Created by Administrator on 2018/2/27.
 */

public class SellPresenter implements MainContract.SellPresenter {
    private MainContract.SellView view;
    private DataSource dataRepository;

    public SellPresenter(DataSource dataRepository, MainContract.SellView view) {
        this.view = view;
        this.dataRepository = dataRepository;
        this.view.setPresenter(this);
    }

    @Override
    public void exChange(String token, String symbol, String price, String amount, String direction, String type) {
        view.displayLoadingPopup();
        dataRepository.exChange(token, symbol, price, amount, direction, type, new DataSource.DataCallback() {
            @Override
            public void onDataLoaded(Object obj) {
                view.hideLoadingPopup();
                view.exChangeSuccess((String) obj);
            }

            @Override
            public void onDataNotAvailable(Integer code, String toastMessage) {
                view.hideLoadingPopup();
                view.exChangeFail(code, toastMessage);

            }
        });
    }

    @Override
    public void walletBase(String token, String coinName) {
        dataRepository.wallet(token, coinName, new DataSource.DataCallback() {
            @Override
            public void onDataLoaded(Object obj) {
                view.walletBaseSuccess((Coin) obj);
            }

            @Override
            public void onDataNotAvailable(Integer code, String toastMessage) {
                view.walletBaseFail(code, toastMessage);
            }
        });
    }

    @Override
    public void walletOther(String token, String coinName) {
        dataRepository.wallet(token, coinName, new DataSource.DataCallback() {
            @Override
            public void onDataLoaded(Object obj) {
                view.walletOtherSuccess((Coin) obj);
            }

            @Override
            public void onDataNotAvailable(Integer code, String toastMessage) {
                view.walletOtherFail(code, toastMessage);

            }
        });
    }

    @Override
    public void plate(String symbol) {
        dataRepository.plate(symbol, new DataSource.DataCallback() {
            @Override
            public void onDataLoaded(Object obj) {
                view.plateSuccess((Plate) obj);
            }

            @Override
            public void onDataNotAvailable(Integer code, String toastMessage) {
                view.plateFail(code, toastMessage);

            }
        });
    }
}
