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

import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.DeleteMapping;
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.ViewedPages;
import com.iqser.red.service.persistence.service.v1.api.shared.model.ViewedPagesRequest;

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

public interface ViewedPagesResource {

    String REST_PATH = ExternalApi.BASE_PATH + "/viewedPages";

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

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

    String PAGE = "page";
    String PAGE_PATH_VARIABLE = "/{" + PAGE + "}";


    @ResponseStatus(value = HttpStatus.NO_CONTENT)
    @Operation(summary = "Adds a page to the viewed pages", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "OK"), @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "400", description = "Invalid file status."), @ApiResponse(responseCode = "403", description = "Forbidden.")})
    @PostMapping(value = REST_PATH + DOSSIER_ID_PATH_VARIABLE + FILE_ID_PATH_VARIABLE, consumes = MediaType.APPLICATION_JSON_VALUE)
    void addPage(@PathVariable(DOSSIER_ID) String dossierId, @PathVariable(FILE_ID) String fileId, @RequestBody ViewedPagesRequest viewedPagesRequest);


    @ResponseStatus(value = HttpStatus.NO_CONTENT)
    @Operation(summary = "Removes a page to the viewed pages", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "OK"), @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "400", description = "Invalid file status."), @ApiResponse(responseCode = "403", description = "Forbidden.")})
    @DeleteMapping(value = REST_PATH + DOSSIER_ID_PATH_VARIABLE + FILE_ID_PATH_VARIABLE + PAGE_PATH_VARIABLE)
    void removePage(@PathVariable(DOSSIER_ID) String dossierId, @PathVariable(FILE_ID) String fileId, @PathVariable(PAGE) int page);


    @ResponseStatus(value = HttpStatus.OK)
    @Operation(summary = "Gets the viewed pages for a file, depending on the users role.", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "400", description = "Invalid file status."), @ApiResponse(responseCode = "403", description = "Forbidden.")})
    @GetMapping(value = REST_PATH + DOSSIER_ID_PATH_VARIABLE + FILE_ID_PATH_VARIABLE, produces = MediaType.APPLICATION_JSON_VALUE)
    ViewedPages getViewedPages(@PathVariable(DOSSIER_ID) String dossierId, @PathVariable(FILE_ID) String fileId);

}
