/*
 * #%L
 * %%
 * Copyright (C) 2020 BMW Car IT GmbH
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
package io.joynr.capabilities;

import io.joynr.proxy.CallbackWithModeledError;
import joynr.types.DiscoveryError;
import joynr.types.GlobalDiscoveryEntry;

public class GcdTask {
    public enum MODE {
        ADD, REMOVE, READD
    }

    static abstract class CallbackCreator {
        public abstract CallbackWithModeledError<Void, DiscoveryError> createCallback();
    }

    public final MODE mode;
    public final CallbackCreator callbackCreator;
    public final CallbackWithModeledError<Void, DiscoveryError> callback;
    public final String participantId;
    public final GlobalDiscoveryEntry globalDiscoveryEntry;
    public final String[] gbids;
    public final long expiryDateMs;
    public final boolean doRetry;

    private GcdTask(MODE mode,
                    CallbackCreator callbackCreator,
                    CallbackWithModeledError<Void, DiscoveryError> callback,
                    String participantId,
                    GlobalDiscoveryEntry globalDiscoveryEntry,
                    String[] gbids,
                    long expiryDateMs,
                    boolean doRetry) {
        this.mode = mode;
        this.callbackCreator = callbackCreator;
        this.callback = callback;
        this.participantId = participantId;
        this.globalDiscoveryEntry = globalDiscoveryEntry;
        this.gbids = gbids;
        this.expiryDateMs = expiryDateMs;
        this.doRetry = doRetry;
    }

    public static GcdTask createAddTask(CallbackCreator callbackCreator,
                                        GlobalDiscoveryEntry globalDiscoveryEntry,
                                        long expiryDateMs,
                                        String[] gbids,
                                        boolean doRetry) {

        String participantId = "";
        return new GcdTask(MODE.ADD,
                           callbackCreator,
                           null,
                           participantId,
                           globalDiscoveryEntry,
                           gbids,
                           expiryDateMs,
                           doRetry);
    }

    public static GcdTask createReaddTask() {
        CallbackWithModeledError<Void, DiscoveryError> callback = null;
        String participantId = "";
        GlobalDiscoveryEntry globalDiscoveryEntry = null;
        String[] gbids = null;
        long expiryDateMs = 0L;
        return new GcdTask(MODE.READD, null, callback, participantId, globalDiscoveryEntry, gbids, expiryDateMs, false);
    }

    public static GcdTask createRemoveTask(CallbackCreator callbackCreator, String participantId) {
        GlobalDiscoveryEntry globalDiscoveryEntry = null;
        long expiryDateMs = 0L;
        String[] gbids = null;
        return new GcdTask(MODE.REMOVE,
                           callbackCreator,
                           null,
                           participantId,
                           globalDiscoveryEntry,
                           gbids,
                           expiryDateMs,
                           true);
    }
}

@@ -1079,82 +1079,8 @@
 or;%0A
-    public final CallbackWithModeledError%3CVoid, DiscoveryError%3E callback;%0A
     
@@ -1110,24 +1110,24 @@
 ticipantId;%0A
+
     public f
@@ -1366,85 +1366,8 @@
 or,%0A
-                    CallbackWithModeledError%3CVoid, DiscoveryError%3E callback,%0A
     
@@ -1659,42 +1659,8 @@
 or;%0A
-        this.callback = callback;%0A
     
@@ -2317,41 +2317,8 @@
 or,%0A
-                           null,%0A
     
@@ -2573,80 +2573,8 @@
 ) %7B%0A
-        CallbackWithModeledError%3CVoid, DiscoveryError%3E callback = null;%0A
     
@@ -2773,18 +2773,8 @@
 ull,
- callback,
  par
@@ -3104,16 +3104,16 @@
 REMOVE,%0A
+
         
@@ -3152,41 +3152,8 @@
 or,%0A
-                           null,%0A
     

Remove unused callback attribute from GCDTask