package kr.co.hanwha.hifive.data.source;

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

import kr.co.hanwha.hifive.data.model.ProfileRoot;
import kr.co.hanwha.hifive.data.source.contract.MyHomeDataSource;
import kr.co.hanwha.hifive.network.HFNetworkUtil;
import kr.co.hanwha.hifive.network.hanwha.HanwhaNetworkCallback;
import kr.co.hanwha.hifive.network.hanwha.HanwhaNetworkError;

/**
 * Created by aaron on 2018. 9. 4.
 */
public class MyHomeDataRepository implements MyHomeDataSource {
    private static MyHomeDataRepository sInstance = null;

    public static MyHomeDataRepository getInstance() {
        if (sInstance == null) {
            sInstance = new MyHomeDataRepository();
        }
        return sInstance;
    }

    @Override
    public void requestMyHomeGetProfile(@NonNull Context context, int selectMemberId, @NonNull final HanwhaNetworkCallback<ProfileRoot> callback) {
        String encryption_member_id = MemberDataRepository.getInstance().getEncryptionMemberId();

        HFNetworkUtil networkUtil = new HFNetworkUtil();
        networkUtil.requestMyHomeGetProfile(context, encryption_member_id, selectMemberId, new HanwhaNetworkCallback<ProfileRoot>() {
            @Override
            public void onSuccess(ProfileRoot response) {
                callback.onSuccess(response);
            }

            @Override
            public void onFailure(HanwhaNetworkError error) {
                if (error != null && error.getStatusCode() == HanwhaNetworkError.CODE_EMPTY_DATA) {
                    callback.onSuccess(null);
                } else
                    callback.onFailure(error);
            }

            @Override
            public void onPreExecute() {
                callback.onPreExecute();
            }

            @Override
            public void onPostExecute() {
                callback.onPostExecute();
            }
        });
    }

    @Override
    public void clearData() {

    }
}
