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.BaseData;
import kr.co.hanwha.hifive.data.model.TaskData;
import kr.co.hanwha.hifive.data.source.contract.TaskStatusDataSource;
import kr.co.hanwha.hifive.enums.TaskEvaluationType;
import kr.co.hanwha.hifive.network.HFNetworkUtil;
import kr.co.hanwha.hifive.network.hanwha.HanwhaNetworkCallback;

public class TaskStatusDataRepository implements TaskStatusDataSource {
    private static TaskStatusDataRepository sInstance = null;

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

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

    @Override
    public void clearData() {

    }

    @Override
    public void requestTaskAccept(@NonNull Context context,
                                  @NonNull TaskData taskData,
                                  @Nullable HanwhaNetworkCallback<BaseData> callback) {
        String encryption_member_id = MemberDataRepository.getInstance().getEncryptionMemberId();
        HFNetworkUtil networkUtil = new HFNetworkUtil();
        networkUtil.requestTaskStatusAccept(context, encryption_member_id, taskData.getAuthor_member_id(), taskData.getTask_id(), callback);
    }

    @Override
    public void requestTaskReject(@NonNull Context context,
                                  @NonNull TaskData taskData,
                                  @NonNull String message,
                                  @Nullable HanwhaNetworkCallback<BaseData> callback) {
        String encryption_member_id = MemberDataRepository.getInstance().getEncryptionMemberId();

        HFNetworkUtil networkUtil = new HFNetworkUtil();
        networkUtil.requestTaskStatusRejectedRequest(context, encryption_member_id, taskData.getAuthor_member_id(), taskData.getTask_id(), message, callback);
    }

    @Override
    public void requestSetTaskDeleteRequest(@NonNull Context context,
                                            @NonNull TaskData taskData,
                                            @Nullable HanwhaNetworkCallback callback) {
        String encryption_member_id = MemberDataRepository.getInstance().getEncryptionMemberId();

        HFNetworkUtil networkUtil = new HFNetworkUtil();
        networkUtil.requestTaskStatusClosed(context, encryption_member_id, taskData.getAuthor_member_id(), taskData.getTask_id(), callback);
    }

    @Override
    public void requestSetTaskReRequest(@NonNull Context context,
                                        @NonNull TaskData taskData,
                                        @Nullable HanwhaNetworkCallback callback) {
        String encryption_member_id = MemberDataRepository.getInstance().getEncryptionMemberId();

        HFNetworkUtil networkUtil = new HFNetworkUtil();
        networkUtil.requestTaskStatusRequest(context, encryption_member_id, taskData.getAuthor_member_id(), taskData.getTask_id(), callback);
    }

    @Override
    public void requestSetTaskEvaluation(@NonNull Context context,
                                         @NonNull TaskData taskData,
                                         @NonNull TaskEvaluationType taskEvaluationType,
                                         @Nullable HanwhaNetworkCallback<BaseData> callback) {
        String encryption_member_id = MemberDataRepository.getInstance().getEncryptionMemberId();
        HFNetworkUtil networkUtil = new HFNetworkUtil();
        networkUtil.requestTaskStatusEvaluated(context, encryption_member_id, taskData.getAuthor_member_id(), taskData.getTask_id(), taskEvaluationType, callback);
    }

    @Override
    public void requestSetTaskEvaluationAccept(@NonNull Context context,
                                               @NonNull TaskData taskData,
                                               @Nullable HanwhaNetworkCallback callback) {
        String encryption_member_id = MemberDataRepository.getInstance().getEncryptionMemberId();

        HFNetworkUtil networkUtil = new HFNetworkUtil();
        networkUtil.requestTaskStatusClosed(context, encryption_member_id, taskData.getAuthor_member_id(), taskData.getTask_id(), callback);
    }

    @Override
    public void requestSetTaskEvaluationReject(@NonNull Context context,
                                               @NonNull TaskData taskData,
                                               @NonNull String message,
                                               @Nullable HanwhaNetworkCallback callback) {
        String encryption_member_id = MemberDataRepository.getInstance().getEncryptionMemberId();

        HFNetworkUtil networkUtil = new HFNetworkUtil();
        networkUtil.requestTaskStatusRejectedEvaluation(context, encryption_member_id, taskData.getAuthor_member_id(), taskData.getTask_id(), message, callback);
    }
}
