// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.api.integration.deployment;

import com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId;
import com.yahoo.vespa.hosted.controller.api.integration.LogEntry;

import java.net.URI;
import java.util.List;

/**
 * Allows running some predefined tests -- typically remotely.
 *
 * @author jonmv
 */
public interface TesterCloud {

    /** Signals the tester to run its tests. */
    void startTests(URI testerUrl, Suite suite, byte[] config);

    /** Signals the tester to run its tests. */
    // TODO: Remove default implementation when implementations have been updated
    default void startTests(DeploymentId deploymentId, Suite suite, byte[] config) {}

    /** Returns the log entries from the tester with ids after the given threshold. */
    List<LogEntry> getLog(URI testerUrl, long after);

    /** Returns the log entries from the tester with ids after the given threshold. */
    // TODO: Remove default implementation when implementations have been updated
    default List<LogEntry> getLog(DeploymentId deploymentId, long after) { return List.of(); }

    /** Returns the current status of the tester. */
    Status getStatus(URI testerUrl);

    /** Returns the current status of the tester. */
    Status getStatus(DeploymentId deploymentId);

    /** Returns whether the container is ready to serve. */
    boolean ready(URI endpointUrl);

    /** Returns whether the test container is ready to serve */
    boolean testerReady(URI endpointUrl);

    /** Returns whether the test container is ready to serve */
    // TODO: Remove default implementation when implementations have been updated
    default boolean testerReady(DeploymentId deploymentId) { return false; }

    /** Returns whether the given URL is registered in DNS. */
    boolean exists(URI endpointUrl);

    /**
     * Returns whether the given URL is registered in DNS. Always returns true,
     * as endpoints are not use in this case
     */
    default boolean exists(DeploymentId deploymentId) { return true; }

    enum Status {

        /** Tests have not yet started. */
        NOT_STARTED,

        /** Tests are running. */
        RUNNING,

        /** Tests failed. */
        FAILURE,

        /** The tester encountered an exception. */
        ERROR,

        /** The tests were successful. */
        SUCCESS

    }


    enum Suite {

        system,

        staging_setup,

        staging,

        production;

        public static Suite of(JobType type, boolean isSetup) {
            if (type == JobType.systemTest) return system;
            if (type == JobType.stagingTest) return isSetup ? staging_setup : staging;
            if (type.isProduction()) return production;
            throw new AssertionError("Unknown JobType '" + type + "'!");
        }

    }

}

@@ -659,98 +659,8 @@
     
-// TODO: Remove default implementation when implementations have been updated%0A    default 
 void
@@ -729,11 +729,9 @@
 fig)
- %7B%7D
+;
 %0A%0A  
@@ -965,98 +965,8 @@
     
-// TODO: Remove default implementation when implementations have been updated%0A    default 
 List
@@ -1025,30 +1025,9 @@
 ter)
- %7B return List.of(); %7D
+;
 %0A%0A  
@@ -1494,98 +1494,8 @@
     
-// TODO: Remove default implementation when implementations have been updated%0A    default 
 bool
@@ -1540,26 +1540,9 @@
 tId)
- %7B return false; %7D
+;
 %0A%0A  

Remove unused default implementations