package kr.co.hanwha.hifive.screen.intro;

import android.app.Activity;
import android.content.Context;
import android.support.annotation.NonNull;

import kr.co.hanwha.hifive.data.source.MemberDataRepository;
import kr.co.hanwha.hifive.network.hanwha.HanwhaNetworkCallback;
import kr.co.hanwha.hifive.network.hanwha.HanwhaNetworkError;
import kr.co.hanwha.hifive.screen.intro.contract.CheckAuthNumberContract;
import kr.co.hanwha.hifive.util.HFInfoUtil;

/**
 * Created by sanghoonkwon on 2018. 2. 13..
 */

public class CheckAuthNumberPresenter implements CheckAuthNumberContract.Presenter {
    private CheckAuthNumberContract.View mView;

    public CheckAuthNumberPresenter(@NonNull CheckAuthNumberContract.View view) {
        mView = view;
    }

    @Override
    public void detachView() {
        mView = null;
    }

    @Override
    public Context getContext() {
        return (Context) mView;
    }

    @Override
    public void doSimpleLogin(@NonNull String authcode) {
        String login_id = HFInfoUtil.getMemberLoginId(getContext());
        MemberDataRepository.getInstance().doSimpleLogin(getContext(), login_id, authcode, new HanwhaNetworkCallback() {
            @Override
            public void onSuccess(Object response) {
                getActivity().finish();
            }

            @Override
            public void onFailure(HanwhaNetworkError error) {
                mView.showAlertMessage(error.getMessage());
            }

            @Override
            public void onPreExecute() {
                mView.showLoadingDialog(true);
            }

            @Override
            public void onPostExecute() {
                mView.showLoadingDialog(false);
            }
        });
    }

    /**************************************************
     * Support methods
     **************************************************/
    private Activity getActivity() {
        return (Activity) mView;
    }
}
