package com.iqser.red.service.persistence.service.v1.api.external.resource;

import com.iqser.red.service.persistence.service.v1.api.shared.model.saas.migration.MigrationStatusResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

public interface MigrationStatusResource {

    String MIGRATION_STATUS_REST_PATH = ExternalApi.BASE_PATH + "/migration-status";
    String START_MIGRATION_REST_PATH = ExternalApi.BASE_PATH + "/start_migration";
    String REVERT_MIGRATION_REST_PATH = ExternalApi.BASE_PATH + "/revert_migration";
    String RETRY_MIGRATION_REST_PATH = ExternalApi.BASE_PATH + "/retry_migration";

    String FILE_ID = "fileId";
    String FILE_ID_PATH_VARIABLE = "/{" + FILE_ID + "}";

    String DOSSIER_ID = "dossierId";
    String DOSSIER_ID_PATH_VARIABLE = "/{" + DOSSIER_ID + "}";


    @ResponseBody
    @PostMapping(value = MIGRATION_STATUS_REST_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
    @Operation(summary = "Show the status of the migration", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Success.")})
    MigrationStatusResponse migrationStatus();


    @ResponseBody
    @PostMapping(value = START_MIGRATION_REST_PATH + FILE_ID_PATH_VARIABLE + DOSSIER_ID_PATH_VARIABLE)
    @Operation(summary = "Start SAAS migration for specific file", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Success.")})
    ResponseEntity<?> startMigrationForFile(@RequestParam(value = DOSSIER_ID) String dossierId, @RequestParam(value = FILE_ID) String fileId);


    @ResponseBody
    @PostMapping(value = REVERT_MIGRATION_REST_PATH + FILE_ID_PATH_VARIABLE + DOSSIER_ID_PATH_VARIABLE)
    @Operation(summary = "Start SAAS migration for specific file", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Success.")})
    ResponseEntity<?> revertMigrationForFile(@RequestParam(value = DOSSIER_ID) String dossierId, @RequestParam(value = FILE_ID) String fileId);


    @ResponseBody
    @PostMapping(value = RETRY_MIGRATION_REST_PATH)
    @Operation(summary = "Restart SAAS migration for all files in error state", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Success.")})
    ResponseEntity<?> requeueErrorFiles();

}
