package org.wso2.carbon.device.mgt.ios.services;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.Authorization;
import io.swagger.annotations.AuthorizationScope;
import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Info;
import io.swagger.annotations.ResponseHeader;
import io.swagger.annotations.SwaggerDefinition;
import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes;
import io.swagger.annotations.Tag;
import org.wso2.carbon.device.mgt.ios.api.utils.beans.OperationStatusBean;
import org.wso2.carbon.device.mgt.ios.util.IOSConstants;

import javax.ws.rs.Consumes;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

/**
 * iOS cellular REST-API implementation.
 */
@SwaggerDefinition(
        info = @Info(
                version = "1.0.0",
                title = "",
                extensions = {
                        @Extension(properties = {
                                @ExtensionProperty(name = "name", value = "iOS Operation Management"),
                                @ExtensionProperty(name = "context", value = "/api/device-mgt/ios/v1.0/operation"),
                        })
                }
        ),
        tags = {
                @Tag(name = "ios,device_management", description = "")
        }
)
@Scopes(scopes = {
        @Scope(
                name = "iOS operation update",
                description = "",
                key = "perm:ios:enroll",
                permissions = {"/device-mgt/devices/enroll/ios"}
        )
}
)
@Api(value = "iOS Operation Management",
     description = "This carries all the resources related to the iOS Operation management functionalities.")
@Path("/operation")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public interface OperationManagementService {

    @PUT
    @Path("/{id}")
    @ApiOperation(
            consumes = MediaType.APPLICATION_JSON,
            httpMethod = "PUT",
            value = "Updating the Status of the Operation.",
            notes = "Update the status of an operation that has been carried out on a device.",
            tags = "IOS Operation Management Service",
            extensions = {
                @Extension(properties = {
                        @ExtensionProperty(name = IOSConstants.SCOPE, value = "perm:ios:enroll")
                })
            }
    )
    @ApiResponses(value = {
            @ApiResponse(
                    code = 200,
                    message = "OK. \n Successfully updated the operation status.",
                    responseHeaders = {
                            @ResponseHeader(
                                    name = "Content-Type",
                                    description = "The content type of the body"),
                            @ResponseHeader(
                                    name = "ETag",
                                    description = "Entity Tag of the response resource.\n" +
                                            "Used by caches, or in conditional requests."),
                            @ResponseHeader(
                                    name = "Last-Modified",
                                    description = "Date and time the resource was last modified.\n" +
                                            "Used by caches, or in conditional requests.")}),
            @ApiResponse(
                    code = 400,
                    message = "Bad Request. \n Invalid request or validation error."),
            @ApiResponse(
                    code = 404,
                    message = "Not Found. \n The specified resource does not exist."),
            @ApiResponse(
                    code = 415,
                    message = "Unsupported media type. \n The format of the requested entity was not supported.\n"),
            @ApiResponse(
                    code = 500,
                    message = "Internal Server Error. \n " +
                            "Server error occurred while updating the status of the operation.")
    })
    Response updateOperationStatus(
            @ApiParam(
                    name = "acceptHeader",
                    value = "Accept header")
            @HeaderParam("Accept") String acceptHeader,
            @ApiParam(
                    name = "id",
                    value = "The device identifier")
            @PathParam("id") String deviceId,
            @ApiParam(
                    name = "OperationStatusBean",
                    value = "The device operation statuses. The operation statuses are listed below:" +
                            "IN-PROGRESS - The operation is processing on the EMM server side and has not yet been " +
                            "delivered to the device.\n" +
                            "PENDING - The operation is delivered to the device but the response from the device is " +
                            "pending.\n" +
                            "COMPLETED - The operation is delivered to the device and the server has received a " +
                            "response back from the device.\n" +
                            "ERROR - An error has occurred while carrying out the operation.")
                    OperationStatusBean operationStatusBean);
}