// Path: plugins-for-tests/dummy-artifact-plugin/src/main/java/cd/go/artifact/dummy/request/FetchArtifactRequest.java
// public class FetchArtifactRequest {
//     @Expose
//     @SerializedName("store_configuration")
//     private ArtifactStoreConfig artifactStoreConfig;
//     @Expose
//     @SerializedName("fetch_artifact_configuration")
//     private FetchArtifact fetchArtifact;
//     @Expose
//     @SerializedName("artifact_metadata")
//     private PublishMetadata metadata;
// 
//     public ArtifactStoreConfig getArtifactStoreConfig() {
//         return artifactStoreConfig;
//     }
// 
//     public PublishMetadata getMetadata() {
//         return metadata;
//     }
// 
//     public static FetchArtifactRequest fromJSON(String json) {
//         return GSON.fromJson(json, FetchArtifactRequest.class);
//     }
// 
//     public FetchArtifact getFetchArtifact() {
//         return fetchArtifact;
//     }
// }
// 
// Path: plugins-for-tests/dummy-artifact-plugin/src/main/java/cd/go/artifact/dummy/request/PublishArtifactRequest.java
// public class PublishArtifactRequest {
//     @Expose
//     @SerializedName("agent_working_directory")
//     private String agentWorkingDir;
// 
//     @Expose
//     @SerializedName("artifact_store")
//     private ArtifactStore artifactStore;
// 
//     @Expose
//     @SerializedName("artifact_plan")
//     private ArtifactPlan artifactPlan;
// 
//     @Expose
//     @SerializedName("environment_variables")
//     private Map<String, String> environmentVariables;
//     private Object jobIdentifier;
// 
//     public PublishArtifactRequest() {
//     }
// 
//     public String getAgentWorkingDir() {
//         return agentWorkingDir;
//     }
// 
//     public ArtifactStore getArtifactStore() {
//         return artifactStore;
//     }
// 
//     public ArtifactPlan getArtifactPlan() {
//         return artifactPlan;
//     }
// 
//     public Map<String, String> getEnvironmentVariables() {
//         return environmentVariables;
//     }
// 
//     public static PublishArtifactRequest fromJSON(String json) {
//         return GSON.fromJson(json, PublishArtifactRequest.class);
//     }
// 
//     public String toJSON() {
//         return GSON.toJson(this);
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (!(o instanceof PublishArtifactRequest)) return false;
// 
//         PublishArtifactRequest that = (PublishArtifactRequest) o;
// 
//         if (agentWorkingDir != null ? !agentWorkingDir.equals(that.agentWorkingDir) : that.agentWorkingDir != null)
//             return false;
//         if (artifactStore != null ? !artifactStore.equals(that.artifactStore) : that.artifactStore != null)
//             return false;
//         return artifactPlan != null ? artifactPlan.equals(that.artifactPlan) : that.artifactPlan == null;
//     }
// 
//     @Override
//     public int hashCode() {
//         int result = agentWorkingDir != null ? agentWorkingDir.hashCode() : 0;
//         result = 31 * result + (artifactStore != null ? artifactStore.hashCode() : 0);
//         result = 31 * result + (artifactPlan != null ? artifactPlan.hashCode() : 0);
//         return result;
//     }
// 
//     public JobIdentifier getJobIdentifier() {
//         return new JobIdentifier(getEnvironmentVariables());
//     }
// }
// 
// Path: plugins-for-tests/dummy-artifact-plugin/src/main/java/cd/go/artifact/dummy/model/ArtifactStoreConfig.java
// public static String artifactStoreMetadata() {
//     return GSON.toJson(Arrays.asList(
//             new Field("Url", new Metadata(true, false)),
//             new Field("Username", new Metadata(true, false)),
//             new Field("Password", new Metadata(true, true))
//     ));
// }


import cd.go.artifact.dummy.model.*;
import cd.go.artifact.dummy.request.FetchArtifactRequest;
import cd.go.artifact.dummy.request.PublishArtifactRequest;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.thoughtworks.go.plugin.api.GoApplicationAccessor;
import com.thoughtworks.go.plugin.api.GoPlugin;
import com.thoughtworks.go.plugin.api.GoPluginIdentifier;
import com.thoughtworks.go.plugin.api.annotation.Extension;
import com.thoughtworks.go.plugin.api.exceptions.UnhandledRequestTypeException;
import com.thoughtworks.go.plugin.api.logging.Logger;
import com.thoughtworks.go.plugin.api.request.GoPluginApiRequest;
import com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse;
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse;
import okhttp3.*;
import java.io.File;
import java.io.IOException;
import java.util.Base64;
import static cd.go.artifact.dummy.model.ArtifactStoreConfig.artifactStoreMetadata;
import static java.lang.String.format;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
            LOG.error("Error while executing request " + request.requestName(), e);
            throw new RuntimeException(e);
        }
    }

    @Override
    public GoPluginIdentifier pluginIdentifier() {
        return new GoPluginIdentifier("artifact", singletonList("2.0"));
    }

    private GoPluginApiResponse fetchArtifact(FetchArtifactRequest fetchArtifactRequest) throws IOException {
        ArtifactStoreConfig artifactStoreConfig = fetchArtifactRequest.getArtifactStoreConfig();
        String artifactPath = fetchArtifactRequest.getFetchArtifact().getPath();
        PublishMetadata metadata = fetchArtifactRequest.getMetadata();

        HttpUrl httpUrl = HttpUrl.parse(artifactStoreConfig.getUrl())
                .newBuilder()
                .addPathSegment("files")
                .addPathSegment(metadata.getJobIdentifier().getPipeline())
                .addPathSegment(metadata.getJobIdentifier().getPipelineCounter())
                .addPathSegment(metadata.getJobIdentifier().getStage())
                .addPathSegment(metadata.getJobIdentifier().getStageCounter())
                .addPathSegment(metadata.getJobIdentifier().getJob())
                .addPathSegments(artifactPath)
                .build();

        Request request = new Request.Builder()
                .url(httpUrl)
                .get()
                .addHeader("Authorization", Credentials.basic(artifactStoreConfig.getUsername(), artifactStoreConfig.getPassword()))
// Path: plugins-for-tests/dummy-artifact-plugin/src/main/java/cd/go/artifact/dummy/request/FetchArtifactRequest.java
// public class FetchArtifactRequest {
//     @Expose
//     @SerializedName("store_configuration")
//     private ArtifactStoreConfig artifactStoreConfig;
//     @Expose
//     @SerializedName("fetch_artifact_configuration")
//     private FetchArtifact fetchArtifact;
//     @Expose
//     @SerializedName("artifact_metadata")
//     private PublishMetadata metadata;
// 
//     public ArtifactStoreConfig getArtifactStoreConfig() {
//         return artifactStoreConfig;
//     }
// 
//     public PublishMetadata getMetadata() {
//         return metadata;
//     }
// 
//     public static FetchArtifactRequest fromJSON(String json) {
//         return GSON.fromJson(json, FetchArtifactRequest.class);
//     }
// 
//     public FetchArtifact getFetchArtifact() {
//         return fetchArtifact;
//     }
// }
// 
// Path: plugins-for-tests/dummy-artifact-plugin/src/main/java/cd/go/artifact/dummy/request/PublishArtifactRequest.java
// public class PublishArtifactRequest {
//     @Expose
//     @SerializedName("agent_working_directory")
//     private String agentWorkingDir;
// 
//     @Expose
//     @SerializedName("artifact_store")
//     private ArtifactStore artifactStore;
// 
//     @Expose
//     @SerializedName("artifact_plan")
//     private ArtifactPlan artifactPlan;
// 
//     @Expose
//     @SerializedName("environment_variables")
//     private Map<String, String> environmentVariables;
//     private Object jobIdentifier;
// 
//     public PublishArtifactRequest() {
//     }
// 
//     public String getAgentWorkingDir() {
//         return agentWorkingDir;
//     }
// 
//     public ArtifactStore getArtifactStore() {
//         return artifactStore;
//     }
// 
//     public ArtifactPlan getArtifactPlan() {
//         return artifactPlan;
//     }
// 
//     public Map<String, String> getEnvironmentVariables() {
//         return environmentVariables;
//     }
// 
//     public static PublishArtifactRequest fromJSON(String json) {
//         return GSON.fromJson(json, PublishArtifactRequest.class);
//     }
// 
//     public String toJSON() {
//         return GSON.toJson(this);
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (!(o instanceof PublishArtifactRequest)) return false;
// 
//         PublishArtifactRequest that = (PublishArtifactRequest) o;
// 
//         if (agentWorkingDir != null ? !agentWorkingDir.equals(that.agentWorkingDir) : that.agentWorkingDir != null)
//             return false;
//         if (artifactStore != null ? !artifactStore.equals(that.artifactStore) : that.artifactStore != null)
//             return false;
//         return artifactPlan != null ? artifactPlan.equals(that.artifactPlan) : that.artifactPlan == null;
//     }
// 
//     @Override
//     public int hashCode() {
//         int result = agentWorkingDir != null ? agentWorkingDir.hashCode() : 0;
//         result = 31 * result + (artifactStore != null ? artifactStore.hashCode() : 0);
//         result = 31 * result + (artifactPlan != null ? artifactPlan.hashCode() : 0);
//         return result;
//     }
// 
//     public JobIdentifier getJobIdentifier() {
//         return new JobIdentifier(getEnvironmentVariables());
//     }
// }
// 
// Path: plugins-for-tests/dummy-artifact-plugin/src/main/java/cd/go/artifact/dummy/model/ArtifactStoreConfig.java
// public static String artifactStoreMetadata() {
//     return GSON.toJson(Arrays.asList(
//             new Field("Url", new Metadata(true, false)),
//             new Field("Username", new Metadata(true, false)),
//             new Field("Password", new Metadata(true, true))
//     ));
// }


// Path: plugins-for-tests/dummy-artifact-plugin/src/main/java/cd/go/artifact/dummy/DummyArtifactPlugin.java
import cd.go.artifact.dummy.model.*;
import cd.go.artifact.dummy.request.FetchArtifactRequest;
import cd.go.artifact.dummy.request.PublishArtifactRequest;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.thoughtworks.go.plugin.api.GoApplicationAccessor;
import com.thoughtworks.go.plugin.api.GoPlugin;
import com.thoughtworks.go.plugin.api.GoPluginIdentifier;
import com.thoughtworks.go.plugin.api.annotation.Extension;
import com.thoughtworks.go.plugin.api.exceptions.UnhandledRequestTypeException;
import com.thoughtworks.go.plugin.api.logging.Logger;
import com.thoughtworks.go.plugin.api.request.GoPluginApiRequest;
import com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse;
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse;
import okhttp3.*;
import java.io.File;
import java.io.IOException;
import java.util.Base64;
import static cd.go.artifact.dummy.model.ArtifactStoreConfig.artifactStoreMetadata;
import static java.lang.String.format;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;

            LOG.error("Error while executing request " + request.requestName(), e);
            throw new RuntimeException(e);
        }
    }

    @Override
    public GoPluginIdentifier pluginIdentifier() {
        return new GoPluginIdentifier("artifact", singletonList("2.0"));
    }

    private GoPluginApiResponse fetchArtifact(FetchArtifactRequest fetchArtifactRequest) throws IOException {
        ArtifactStoreConfig artifactStoreConfig = fetchArtifactRequest.getArtifactStoreConfig();
        String artifactPath = fetchArtifactRequest.getFetchArtifact().getPath();
        PublishMetadata metadata = fetchArtifactRequest.getMetadata();

        HttpUrl httpUrl = HttpUrl.parse(artifactStoreConfig.getUrl())
                .newBuilder()
                .addPathSegment("files")
                .addPathSegment(metadata.getJobIdentifier().getPipeline())
                .addPathSegment(metadata.getJobIdentifier().getPipelineCounter())
                .addPathSegment(metadata.getJobIdentifier().getStage())
                .addPathSegment(metadata.getJobIdentifier().getStageCounter())
                .addPathSegment(metadata.getJobIdentifier().getJob())
                .addPathSegments(artifactPath)
                .build();

        Request request = new Request.Builder()
                .url(httpUrl)
                .get()
                .addHeader("Authorization", Credentials.basic(artifactStoreConfig.getUsername(), artifactStoreConfig.getPassword()))
                .addHeader("Confirm", "true")