/*
 * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
 *
 * WSO2 LLC. licenses this file to you 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.
 */

package org.wso2.carbon.identity.rest.api.server.workflow.v1;

import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import java.io.InputStream;
import java.util.List;

import org.wso2.carbon.identity.rest.api.server.workflow.v1.model.Error;
import org.wso2.carbon.identity.rest.api.server.workflow.v1.model.InstanceStatus;
import org.wso2.carbon.identity.rest.api.server.workflow.v1.model.WorkflowInstanceListResponse;
import org.wso2.carbon.identity.rest.api.server.workflow.v1.model.WorkflowInstanceResponse;
import org.wso2.carbon.identity.rest.api.server.workflow.v1.WorkflowInstancesApiService;
import org.wso2.carbon.identity.rest.api.server.workflow.v1.factories.WorkflowInstancesApiServiceFactory;

import javax.validation.Valid;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import io.swagger.annotations.*;

import javax.validation.constraints.*;

@Path("/workflow-instances")
@Api(description = "The workflow-instances API")

public class WorkflowInstancesApi  {

    private final WorkflowInstancesApiService delegate;

    public WorkflowInstancesApi() {

        this.delegate = WorkflowInstancesApiServiceFactory.getWorkflowInstancesApi();
    }

    @Valid
    @POST
    @Path("/{instance_id}/abort")
    
    @Produces({ "application/json" })
    @ApiOperation(value = "Abort a workflow instance by ID", notes = "Abort a workflow instance by providing the instance ID.  <b>Scope required:</b> internal_workflow_instance_update ", response = InstanceStatus.class, authorizations = {
        @Authorization(value = "BasicAuth"),
        @Authorization(value = "OAuth2", scopes = {
            
        })
    }, tags={ "Workflow Instances Management", })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "Successfully aborted the workflow instance", response = InstanceStatus.class),
        @ApiResponse(code = 400, message = "Invalid input request", response = Error.class),
        @ApiResponse(code = 404, message = "The specified resource is not found", response = Error.class),
        @ApiResponse(code = 500, message = "Internal Server Error", response = Error.class)
    })
    public Response abortWorkflowInstance(@ApiParam(value = "",required=true) @PathParam("instance_id") String instanceId) {

        return delegate.abortWorkflowInstance(instanceId );
    }

    @Valid
    @DELETE
    @Path("/{instance_id}")
    
    @Produces({ "application/json" })
    @ApiOperation(value = "Delete workflow instance by ID", notes = "Delete a workflow instance by providing the instance ID.  <b>Scope required:</b> internal_workflow_instance_delete ", response = Void.class, authorizations = {
        @Authorization(value = "BasicAuth"),
        @Authorization(value = "OAuth2", scopes = {
            
        })
    }, tags={ "Workflow Instances Management", })
    @ApiResponses(value = { 
        @ApiResponse(code = 204, message = "Successfully deleted the workflow instance", response = Void.class),
        @ApiResponse(code = 404, message = "The specified resource is not found", response = Error.class)
    })
    public Response deleteWorkflowInstance(@ApiParam(value = "",required=true) @PathParam("instance_id") String instanceId) {

        return delegate.deleteWorkflowInstance(instanceId );
    }

    @Valid
    @GET
    @Path("/{instance_id}")
    
    @Produces({ "application/json" })
    @ApiOperation(value = "Get workflow instance by ID", notes = "Retrieve a specific workflow instance by providing its unique ID.  <b>Scope required:</b> internal_workflow_instance_view ", response = WorkflowInstanceResponse.class, authorizations = {
        @Authorization(value = "BasicAuth"),
        @Authorization(value = "OAuth2", scopes = {
            
        })
    }, tags={ "Workflow Instances Management", })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "Workflow instance retrieved successfully", response = WorkflowInstanceResponse.class),
        @ApiResponse(code = 404, message = "The specified resource is not found", response = Error.class)
    })
    public Response getWorkflowInstanceById(@ApiParam(value = "",required=true) @PathParam("instance_id") String instanceId) {

        return delegate.getWorkflowInstanceById(instanceId );
    }

    @Valid
    @GET
    
    
    @Produces({ "application/json" })
    @ApiOperation(value = "Get workflow instances for a tenant", notes = "Retrieve workflow instances filtered by various parameters.  <b>Scope required:</b> internal_workflow_instance_view ", response = WorkflowInstanceListResponse.class, authorizations = {
        @Authorization(value = "BasicAuth"),
        @Authorization(value = "OAuth2", scopes = {
            
        })
    }, tags={ "Workflow Instances Management" })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "Workflow instances retrieved successfully", response = WorkflowInstanceListResponse.class),
        @ApiResponse(code = 400, message = "Invalid input request", response = Error.class),
        @ApiResponse(code = 401, message = "Unauthorized", response = Void.class),
        @ApiResponse(code = 403, message = "Forbidden", response = Void.class),
        @ApiResponse(code = 404, message = "The specified resource is not found", response = Error.class),
        @ApiResponse(code = 500, message = "Internal Server Error", response = Error.class)
    })
    public Response getWorkflowInstances(    @Valid@ApiParam(value = "", defaultValue="25") @DefaultValue("25")  @QueryParam("limit") Integer limit,     @Valid@ApiParam(value = "", defaultValue="0") @DefaultValue("0")  @QueryParam("offset") Integer offset,     @Valid@ApiParam(value = "Filter conditions using logical expressions. Supported operators: `eq`, `le`, `ge`.  Combine multiple conditions with `and`.  Example:      `operationType+eq+ADD_USER+and+requestType+eq+MY_TASKS+and+status+eq+PENDING+and+createdAt+ge+2025-06-01 09:57:47.000+and+createdAt+le+2025-07-31 09:57:47.000` ")  @QueryParam("filter") String filter) {

        return delegate.getWorkflowInstances(limit,  offset,  filter );
    }

}
