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

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

import kr.co.hanwha.hifive.data.model.MessageAddData;
import kr.co.hanwha.hifive.data.model.MessageListRoot;
import kr.co.hanwha.hifive.data.source.contract.TaskMessageDataSource;
import kr.co.hanwha.hifive.network.HFNetworkUtil;
import kr.co.hanwha.hifive.network.hanwha.HanwhaNetworkCallback;

public class TaskMessageDataRepository implements TaskMessageDataSource {
    private static TaskMessageDataRepository sInstance = null;

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

    public static void destroyInstance() {
        sInstance = null;
    }


    @Override
    public void clearData() {

    }

    @Override
    public void requestGetMessageList(@NonNull Context context,
                                      @NonNull int task_id,
                                      @NonNull int current_page,
                                      @Nullable final HanwhaNetworkCallback<MessageListRoot> callback) {
        String encryption_member_id = MemberDataRepository.getInstance().getEncryptionMemberId();
        HFNetworkUtil networkUtil = new HFNetworkUtil();
        networkUtil.requestGetMessageList(context, encryption_member_id, task_id, current_page, callback);
    }

    @Override
    public void requestAddMessage(@NonNull Context context,
                                  @NonNull int task_id,
                                  @NonNull String contents,
                                  @Nullable HanwhaNetworkCallback<MessageAddData> callback) {
        String encryption_member_id = MemberDataRepository.getInstance().getEncryptionMemberId();
        HFNetworkUtil networkUtil = new HFNetworkUtil();
        networkUtil.requestAddMessage(context, encryption_member_id, task_id, contents, callback);
    }

    @Override
    public void requestDeleteMessage(@NonNull Context context,
                                     @NonNull int id,
                                     @Nullable HanwhaNetworkCallback callback) {
        String encryption_member_id = MemberDataRepository.getInstance().getEncryptionMemberId();
        HFNetworkUtil networkUtil = new HFNetworkUtil();
        networkUtil.requestDeleteMessage(context, encryption_member_id, id, callback);
    }
}
