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.PutMapping;
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.DigitalSignatureKms;
import com.iqser.red.service.persistence.service.v1.api.shared.model.DigitalSignatureKmsViewModel;
import com.iqser.red.service.persistence.service.v1.api.shared.model.DigitalSignatureViewModel;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.configuration.DigitalSignature;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.configuration.DigitalSignatureType;

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 DigitalSignatureResource {

    String DIGITAL_SIGNATURE_PATH = ExternalApi.BASE_PATH + "/digital-signature";
    String DIGITAL_SIGNATURE_KMS_PATH = DIGITAL_SIGNATURE_PATH + "/kms";
    String DIGITAL_SIGNATURE_TYPE_PATH = DIGITAL_SIGNATURE_PATH + "/type";

    String DIGITAL_SIGNATURE_TYPE = "digitalSignatureType";
    String DIGITAL_SIGNATURE_TYPE_VARIABLE = "/{" + DIGITAL_SIGNATURE_TYPE + "}";


    @Operation(summary = "Gets which digital signature is used to sign PDF's", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "OK"), @ApiResponse(responseCode = "403", description = "Forbidden.")})
    @GetMapping(value = DIGITAL_SIGNATURE_TYPE_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
    DigitalSignatureType getActiveDigitalSignatureType();


    @Operation(summary = "Sets which digital signature is used to sign PDF's", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "OK"), @ApiResponse(responseCode = "400", description = "Invalid Data."), @ApiResponse(responseCode = "403", description = "Forbidden.")})
    @ResponseStatus(HttpStatus.NO_CONTENT)
    @PostMapping(value = DIGITAL_SIGNATURE_TYPE_PATH + DIGITAL_SIGNATURE_TYPE_VARIABLE)
    void setActiveDigitalSignatureType(@PathVariable(DIGITAL_SIGNATURE_TYPE) DigitalSignatureType digitalSignatureType);


    @Operation(summary = "Save a new digital signature used to sign PDF's", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "OK"), @ApiResponse(responseCode = "400", description = "Invalid Digital Signature Data."), @ApiResponse(responseCode = "403", description = "Forbidden.")})
    @ResponseStatus(HttpStatus.CREATED)
    @PostMapping(value = DIGITAL_SIGNATURE_PATH, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    DigitalSignatureViewModel saveDigitalSignature(@RequestBody DigitalSignature digitalSignatureModel);


    @Operation(summary = "Update the digital signature used to sign PDF's", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "OK"), @ApiResponse(responseCode = "400", description = "Invalid Digital Signature Data."), @ApiResponse(responseCode = "403", description = "Forbidden.")})
    @ResponseStatus(HttpStatus.CREATED)
    @PutMapping(value = DIGITAL_SIGNATURE_PATH, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    void updateDigitalSignature(@RequestBody DigitalSignatureViewModel digitalSignatureModel);


    @Operation(summary = "Get the current digital signature", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "403", description = "Forbidden.")})
    @GetMapping(value = DIGITAL_SIGNATURE_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
    DigitalSignatureViewModel getDigitalSignature();


    @Operation(summary = "Remove the digital signature", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "OK"), @ApiResponse(responseCode = "403", description = "Forbidden.")})
    @ResponseStatus(HttpStatus.NO_CONTENT)
    @DeleteMapping(value = DIGITAL_SIGNATURE_PATH)
    void deleteDigitalSignature();


    @Operation(summary = "Save a new digital KMS signature used to sign PDF's", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "OK"), @ApiResponse(responseCode = "400", description = "Invalid Digital Signature Data."), @ApiResponse(responseCode = "403", description = "Forbidden.")})
    @ResponseStatus(HttpStatus.CREATED)
    @PostMapping(value = DIGITAL_SIGNATURE_KMS_PATH, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    DigitalSignatureKmsViewModel saveDigitalSignatureKms(@RequestBody DigitalSignatureKms digitalSignature);


    @Operation(summary = "Get the current digital KMS signature", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "403", description = "Forbidden.")})
    @GetMapping(value = DIGITAL_SIGNATURE_KMS_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
    DigitalSignatureKmsViewModel getDigitalSignatureKms();


    @Operation(summary = "Remove the digital KMS signature", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "OK"), @ApiResponse(responseCode = "403", description = "Forbidden.")})
    @ResponseStatus(HttpStatus.NO_CONTENT)
    @DeleteMapping(value = DIGITAL_SIGNATURE_KMS_PATH)
    void deleteDigitalSignatureKms();

}
