/*
 * Copyright 2018-2024 adorsys GmbH & Co KG
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version. This program is distributed in the hope that
 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see https://www.gnu.org/licenses/.
 *
 * This project is also available under a separate commercial license. You can
 * contact us at sales@adorsys.com.
 */

/**
 * NOTE: This class is auto generated by the swagger code generator program (3.0.35-SNAPSHOT).
 * https://github.com/swagger-api/swagger-codegen
 * Do not edit the class manually.
 */
package de.adorsys.psd2.api;

import com.fasterxml.jackson.databind.ObjectMapper;
import de.adorsys.psd2.model.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.IOException;
import java.util.Optional;
import java.util.UUID;

@jakarta.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2022-05-06T12:59:08.054254+03:00[Europe/Kiev]")
@Validated
public interface ListOfTrustedBeneficiariesApi {

    Logger log = LoggerFactory.getLogger(ListOfTrustedBeneficiariesApi.class);

    default Optional<ObjectMapper> getObjectMapper(){
        return Optional.empty();
    }

    default Optional<HttpServletRequest> getRequest(){
        return Optional.empty();
    }

    default Optional<String> getAcceptHeader() {
        return getRequest().map(r -> r.getHeader("Accept"));
    }

    @Operation(summary = "GET List of trusted beneficiaries", description = "Reads the list of trusted beneficiaries related to the PSU who has given the (explicit) consent. ", tags={ "List of trusted beneficiaries" })
    @ApiResponses(value = {
        @ApiResponse(responseCode = "200", description = "OK", content = @Content(mediaType = "application/json", schema = @Schema(implementation = TrustedBeneficiaries.class))),

        @ApiResponse(responseCode = "400", description = "Validation error occurred. This code will cover malformed syntax in request or incorrect data in payload.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Error400NGLTB.class))),

        @ApiResponse(responseCode = "401", description = "The TPP or the PSU is not correctly authorized to perform the request. Retry the request with correct authentication information.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Error401NGLTB.class))),

        @ApiResponse(responseCode = "403", description = "Returned if the resource that was referenced in the path exists but cannot be accessed by the ASPSP. This code should only be used for non-sensitive id references as it will reveal that the resource exists even though it cannot be accessed.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Error403NGLTB.class))),

        @ApiResponse(responseCode = "404", description = "Returned if the endpoint that was referenced in the path does not exist or cannot be referenced by the ASPSP. When in doubt if a specific id in the path is sensitive or not, use the HTTP response code 404 instead of the HTTP response code 403.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Error404NGLTB.class))),

        @ApiResponse(responseCode = "405", description = "This code is only sent when the HTTP method (PUT, POST, DELETE, GET etc.) is not supported on a specific endpoint.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Error405NGLTB.class))),

        @ApiResponse(responseCode = "408", description = "The server is still working correctly, but an individual request has timed out."),

        @ApiResponse(responseCode = "415", description = "The ASPSP has supplied a media type which the TPP does not support."),

        @ApiResponse(responseCode = "500", description = "Internal server error occurred."),

        @ApiResponse(responseCode = "503", description = "The TPP server is currently unavailable. Generally, this is a temporary state.") })
    @RequestMapping(value = "/v1/trusted-beneficiaries",
        produces = { "application/json", "application/problem+json" },
        method = RequestMethod.GET)
    default ResponseEntity<TrustedBeneficiaries> _listOfTrustedBeneficiaries(
        @Parameter(in = ParameterIn.QUERY, description = "This identification is denoting the addressed account. The account-id is retrieved by using a \"Read account list\" call. The account-id is the \"id\" attribute of the account structure. Its value is constant at least throughout the lifecycle of a given consent. " ,schema=@Schema()) @Valid @RequestParam(value = "account-id", required = false) String accountId,
        @Parameter(in = ParameterIn.HEADER, description = "ID of the request, unique to the call, as determined by the initiating party." ,required=true,schema=@Schema()) @RequestHeader(value="X-Request-ID", required=true) UUID xRequestID,
        @Parameter(in = ParameterIn.HEADER, description = "This then contains the consentId of the related AIS consent, which was performed prior to this payment initiation. " ,required=true,schema=@Schema()) @RequestHeader(value="Consent-ID", required=true) String consentID,
        @Parameter(in = ParameterIn.HEADER, description = "The forwarded IP Address header field consists of the corresponding http request IP Address field between PSU and TPP. " ,schema=@Schema()) @RequestHeader(value="PSU-IP-Address", required=false) String psUIPAddress,
        @Parameter(in = ParameterIn.HEADER, description = "This field  might be used in case where a consent was agreed between ASPSP and PSU through an OAuth2 based protocol, facilitated by the TPP. " ,schema=@Schema()) @RequestHeader(value="Authorization", required=false) String authorization) {
        return listOfTrustedBeneficiaries(accountId, xRequestID, consentID, psUIPAddress, authorization);
    }

    // Override this method
    default ResponseEntity<TrustedBeneficiaries> listOfTrustedBeneficiaries(String accountId,UUID xRequestID,String consentID,String psUIPAddress,String authorization) {
        if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
            if (getAcceptHeader().get().contains("application/json")) {
                try {
                    return new ResponseEntity<>(getObjectMapper().get().readValue("{\n  \"trustedBeneficiaries\" : [ {\n    \"debtorAccount\" : {\n      \"bban\" : \"BARC12345612345678\",\n      \"maskedPan\" : \"123456xxxxxx1234\",\n      \"iban\" : \"FR7612345987650123456789014\",\n      \"currency\" : \"EUR\",\n      \"pan\" : \"5409050000000000\",\n      \"msisdn\" : \"+49 170 1234567\"\n    },\n    \"creditorAddress\" : {\n      \"street\" : \"rue blue\",\n      \"buildingnNumber\" : \"89\",\n      \"city\" : \"Paris\",\n      \"postalCode\" : \"75000\",\n      \"country\" : \"FR\"\n    },\n    \"trustedBeneficiaryId\" : \"74a55404-4ad0-4432-bcf4-93fb94b81e94\",\n    \"creditorName\" : \"Creditor Name\",\n    \"creditorAgent\" : \"AAAADEBBXXX\",\n    \"creditorAlias\" : \"Creditor Alias\",\n    \"creditorId\" : \"Creditor Id 5678\"\n  }, {\n    \"debtorAccount\" : {\n      \"bban\" : \"BARC12345612345678\",\n      \"maskedPan\" : \"123456xxxxxx1234\",\n      \"iban\" : \"FR7612345987650123456789014\",\n      \"currency\" : \"EUR\",\n      \"pan\" : \"5409050000000000\",\n      \"msisdn\" : \"+49 170 1234567\"\n    },\n    \"creditorAddress\" : {\n      \"street\" : \"rue blue\",\n      \"buildingnNumber\" : \"89\",\n      \"city\" : \"Paris\",\n      \"postalCode\" : \"75000\",\n      \"country\" : \"FR\"\n    },\n    \"trustedBeneficiaryId\" : \"74a55404-4ad0-4432-bcf4-93fb94b81e94\",\n    \"creditorName\" : \"Creditor Name\",\n    \"creditorAgent\" : \"AAAADEBBXXX\",\n    \"creditorAlias\" : \"Creditor Alias\",\n    \"creditorId\" : \"Creditor Id 5678\"\n  } ]\n}", TrustedBeneficiaries.class), HttpStatus.NOT_IMPLEMENTED);
                } catch (IOException e) {
                    log.error("Couldn't serialize response for content type application/json", e);
                    return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
                }
            }
        } else {
            log.warn("ObjectMapper or HttpServletRequest not configured in default ListOfTrustedBeneficiariesApi interface so no example is generated");
        }
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
    }

}

