// Copyright 2017 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.application.v4;

import com.fasterxml.jackson.databind.JsonNode;
import com.yahoo.vespa.hosted.controller.api.application.v4.model.DeployResult;
import com.yahoo.vespa.hosted.controller.api.application.v4.model.InstanceInformation;
import com.yahoo.vespa.hosted.controller.api.identifiers.ApplicationId;
import com.yahoo.vespa.hosted.controller.api.identifiers.EnvironmentId;
import com.yahoo.vespa.hosted.controller.api.identifiers.Hostname;
import com.yahoo.vespa.hosted.controller.api.identifiers.InstanceId;
import com.yahoo.vespa.hosted.controller.api.identifiers.RegionId;
import com.yahoo.vespa.hosted.controller.api.identifiers.TenantId;
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import java.io.InputStream;

/**
 * @author Tony Vaagenes
 * @author gv
 */
@Path("") //Ensures that the produces annotation is inherited
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public interface EnvironmentResource {

    String API_PATH = "environment";

    String APPLICATION_TEST_ZIP = "applicationTestZip";
    String APPLICATION_ZIP = "applicationZip";
    String DEPLOY_OPTIONS = "deployOptions";
    String SUBMIT_OPTIONS = "submitOptions";

    @POST
    @Path("{environmentId}/region/{regionId}/instance/{instanceId}/deploy")
    @Consumes({MediaType.MULTIPART_FORM_DATA})
    DeployResult deploy(@PathParam("tenantId") TenantId tenantId,
                        @PathParam("applicationId") ApplicationId applicationId,
                        @PathParam("environmentId") EnvironmentId environmentId,
                        @PathParam("regionId") RegionId regionId,
                        @PathParam("instanceId") InstanceId instanceId,
                        @FormDataParam(APPLICATION_ZIP) InputStream applicationZipFile,
                        @FormDataParam(APPLICATION_ZIP) FormDataContentDisposition fileMetaData,
                        @FormDataParam(DEPLOY_OPTIONS) FormDataBodyPart deployOptions);

    @DELETE
    @Path("{environmentId}/region/{regionId}/instance/{instanceId}")
    String deactivate(@PathParam("tenantId") TenantId tenantId,
                      @PathParam("applicationId") ApplicationId applicationId,
                      @PathParam("environmentId") EnvironmentId environmentId,
                      @PathParam("regionId") RegionId regionId,
                      @PathParam("instanceId") InstanceId instanceId);

    @POST
    @Path("{environmentId}/region/{regionId}/instance/{instanceId}/restart")
    String restart(@PathParam("tenantId") TenantId tenantId,
                   @PathParam("applicationId") ApplicationId applicationId,
                   @PathParam("environmentId") EnvironmentId environmentId,
                   @PathParam("regionId") RegionId regionId,
                   @PathParam("instanceId") InstanceId instanceId,
                   @QueryParam("hostname") Hostname hostname);

    @GET
    @Path("{environmentId}/region/{regionId}/instance/{instanceId}")
    InstanceInformation instanceInfo(@PathParam("tenantId") TenantId tenantId,
                                     @PathParam("applicationId") ApplicationId applicationId,
                                     @PathParam("environmentId") EnvironmentId environmentId,
                                     @PathParam("regionId") RegionId regionId,
                                     @PathParam("instanceId") InstanceId instanceId);

    @GET
    @Path("{environmentId}/region/{regionId}/instance/{instanceId}/converge")
    JsonNode waitForConfigConverge(@PathParam("tenantId") TenantId tenantId,
                                   @PathParam("applicationId") ApplicationId applicationId,
                                   @PathParam("environmentId") EnvironmentId environmentId,
                                   @PathParam("regionId") RegionId regionId,
                                   @PathParam("instanceId") InstanceId instanceId,
                                   @QueryParam("timeout") long timeoutInSeconds);

    @Path("{environmentId}/region/{regionId}/instance/{instanceId}/service")
    ServiceViewResource service();

    @PUT
    @Path("{environmentId}/region/{regionId}/instance/{instanceId}/global-rotation/override")
    String setRotationOut(@PathParam("tenantId") TenantId tenantId,
                          @PathParam("applicationId") ApplicationId applicationId,
                          @PathParam("environmentId") EnvironmentId environmentId,
                          @PathParam("regionId") RegionId regionId,
                          @PathParam("instanceId") InstanceId instanceId);

    @DELETE
    @Path("{environmentId}/region/{regionId}/instance/{instanceId}/global-rotation/override")
    String setRotationIn(@PathParam("tenantId") TenantId tenantId,
                         @PathParam("applicationId") ApplicationId applicationId,
                         @PathParam("environmentId") EnvironmentId environmentId,
                         @PathParam("regionId") RegionId regionId,
                         @PathParam("instanceId") InstanceId instanceId);

}

@@ -227,88 +227,8 @@
 de;%0A
-import com.yahoo.vespa.hosted.controller.api.application.v4.model.DeployResult;%0A
 impo
@@ -306,24 +306,24 @@
 nformation;%0A
+
 import com.y
@@ -727,201 +727,8 @@
 tId;
-%0Aimport org.glassfish.jersey.media.multipart.FormDataBodyPart;%0Aimport org.glassfish.jersey.media.multipart.FormDataContentDisposition;%0Aimport org.glassfish.jersey.media.multipart.FormDataParam;
 %0A%0Aim
@@ -1007,36 +1007,8 @@
 ype;
-%0Aimport java.io.InputStream;
 %0A%0A/*
@@ -1386,858 +1386,40 @@
 ing 
-DEPLOY_OPTIONS = %22deployOptions%22;%0A    String SUBMIT_OPTIONS = %22submitOptions%22;%0A%0A    @POST%0A    @Path(%22%7BenvironmentId%7D/region/%7BregionId%7D/instance/%7BinstanceId%7D/deploy%22)%0A    @Consumes(%7BMediaType.MULTIPART_FORM_DATA%7D)%0A    DeployResult deploy(@PathParam(%22tenantId%22) TenantId tenantId,%0A                        @PathParam(%22applicationId%22) ApplicationId applicationId,%0A                        @PathParam(%22environmentId%22) EnvironmentId environmentId,%0A                        @PathParam(%22regionId%22) RegionId regionId,%0A                        @PathParam(%22instanceId%22) InstanceId instanceId,%0A                        @FormDataParam(APPLICATION_ZIP) InputStream applicationZipFile,%0A                        @FormDataParam(APPLICATION_ZIP) FormDataContentDisposition fileMetaData,%0A                        @FormDataParam(DEPLOY_OPTIONS) FormDataBodyPart deployOptions)
+SUBMIT_OPTIONS = %22submitOptions%22
 ;%0A%0A 

Remove EnvironmentResourc.deploy (unused)