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

import java.util.List;
import java.util.Set;

import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import com.iqser.red.service.persistence.service.v1.api.shared.model.permission.CustomPermissionMappingModel;

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

@ResponseStatus(value = HttpStatus.OK)
public interface CustomPermissionMappingResource {

    String PERMISSION_REST_PATH = ExternalApi.BASE_PATH + "/permissions";
    String TARGET_OBJECT_REST_PATH = "/target-object";
    String SYNC_REST_PATH = "/sync";
    String MAPPING_PERMISSIONS_PATH = "/mapping";

    String TARGET_OBJECT_NAME = "targetObject";
    String TARGET_OBJECT_VARIABLE = "/{" + TARGET_OBJECT_NAME + "}";


    @GetMapping(value = PERMISSION_REST_PATH + TARGET_OBJECT_VARIABLE, produces = MediaType.APPLICATION_JSON_VALUE)
    @Operation(summary = "Get custom permission mappings for a specific object type.", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Successfully returned the mappings")})
    List<CustomPermissionMappingModel> getCustomPermissionMappings(@PathVariable(TARGET_OBJECT_NAME) String targetObject);


    @ResponseStatus(HttpStatus.NO_CONTENT)

    @PostMapping(value = PERMISSION_REST_PATH + TARGET_OBJECT_VARIABLE, consumes = MediaType.APPLICATION_JSON_VALUE)
    @Operation(summary = "Saves the custom permission mappings for a specific object type, overriding existing mappings.", description = "None")
    void saveCustomPermissionMappings(@PathVariable(TARGET_OBJECT_NAME) String targetObject, @RequestBody List<CustomPermissionMappingModel> customPermissionMappingModels);


    @GetMapping(value = PERMISSION_REST_PATH + TARGET_OBJECT_VARIABLE + MAPPING_PERMISSIONS_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
    @Operation(summary = "Returns the required existing permissions defined for a target object, mapped to possible granting permissions.", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Successfully returned the valid mapping")})
    List<CustomPermissionMappingModel> getValidMapping(@PathVariable(TARGET_OBJECT_NAME) String targetObject);


    @GetMapping(value = PERMISSION_REST_PATH + TARGET_OBJECT_REST_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
    @Operation(summary = "Returns all supported target objects ( I.E. dossier, file, etc. )", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Successfully returned the target objects")})
    Set<String> getAllSupportedTargetObjects();


    @ResponseStatus(HttpStatus.NO_CONTENT)
    @PostMapping(value = PERMISSION_REST_PATH + SYNC_REST_PATH)
    @Operation(summary = "Sync all custom permissions", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Successfully synced all permissions")})
    void syncAllCustomPermissions();

}
