// Path: src/main/java/com/mpalourdio/springboottemplate/mediatype/MediaType.java
// public final class MediaType extends org.springframework.http.MediaType {
// 
//     public static final org.springframework.http.MediaType APPLICATION_VND_API_V1;
//     public static final String APPLICATION_VND_API_V1_VALUE = "application/vnd.api.v1+json;charset=UTF-8";
// 
//     public static final org.springframework.http.MediaType APPLICATION_VND_API_V2;
//     public static final String APPLICATION_VND_API_V2_VALUE = "application/vnd.api.v2+json;charset=UTF-8";
// 
//     private MediaType(String type) {
//         super(type);
//     }
// 
//     static {
//         var applicationType = "application";
//         APPLICATION_VND_API_V1 = new org.springframework.http.MediaType(applicationType, "vnd.api.v1+json", StandardCharsets.UTF_8);
//         APPLICATION_VND_API_V2 = new org.springframework.http.MediaType(applicationType, "vnd.api.v2+json", StandardCharsets.UTF_8);
//     }
// }
// 
// Path: src/main/java/com/mpalourdio/springboottemplate/properties/MarvelProperties.java
// @Getter
// @AllArgsConstructor
// @ConstructorBinding
// @ConfigurationProperties("marvel")
// public class MarvelProperties {
// 
//     private final String privatekey;
//     private final String publickey;
//     private final String unknownProperty;
// }


import com.mpalourdio.springboottemplate.mediatype.MediaType;
import com.mpalourdio.springboottemplate.properties.MarvelProperties;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.util.Arrays;
/*
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package com.mpalourdio.springboottemplate.controllers;



@RestController
@RequestMapping("/marvel")
@EnableConfigurationProperties(MarvelProperties.class)
public class MarvelController {

    private final MarvelProperties marvelProperties;
    private final HttpHeaders addonHeaders = new HttpHeaders();

    public MarvelController(MarvelProperties marvelProperties) {
        this.marvelProperties = marvelProperties;
        buildAddonsHeaders(marvelProperties);
    }

    private void buildAddonsHeaders(MarvelProperties marvelProperties) {
        var unkownProperty = marvelProperties.getUnknownProperty();

        if (StringUtils.isNotBlank(unkownProperty)) {
            Arrays.asList(unkownProperty.split(",")).forEach(h -> {
                var split = h.split("=");
                addonHeaders.add(split[0], split[1]);
            });
        }
    }

    @GetMapping(value = "/all", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<String> allCharacters() {
        var restTemplate = new RestTemplate();
        var timestamp = String.valueOf(System.currentTimeMillis() / 1000);
        var hash = DigestUtils.md5Hex(timestamp + marvelProperties.getPrivatekey() + marvelProperties.getPublickey());
        var uri = "http://gateway.marvel.com/v1/public/characters/1009220?apikey="
// Path: src/main/java/com/mpalourdio/springboottemplate/mediatype/MediaType.java
// public final class MediaType extends org.springframework.http.MediaType {
// 
//     public static final org.springframework.http.MediaType APPLICATION_VND_API_V1;
//     public static final String APPLICATION_VND_API_V1_VALUE = "application/vnd.api.v1+json;charset=UTF-8";
// 
//     public static final org.springframework.http.MediaType APPLICATION_VND_API_V2;
//     public static final String APPLICATION_VND_API_V2_VALUE = "application/vnd.api.v2+json;charset=UTF-8";
// 
//     private MediaType(String type) {
//         super(type);
//     }
// 
//     static {
//         var applicationType = "application";
//         APPLICATION_VND_API_V1 = new org.springframework.http.MediaType(applicationType, "vnd.api.v1+json", StandardCharsets.UTF_8);
//         APPLICATION_VND_API_V2 = new org.springframework.http.MediaType(applicationType, "vnd.api.v2+json", StandardCharsets.UTF_8);
//     }
// }
// 
// Path: src/main/java/com/mpalourdio/springboottemplate/properties/MarvelProperties.java
// @Getter
// @AllArgsConstructor
// @ConstructorBinding
// @ConfigurationProperties("marvel")
// public class MarvelProperties {
// 
//     private final String privatekey;
//     private final String publickey;
//     private final String unknownProperty;
// }


// Path: src/main/java/com/mpalourdio/springboottemplate/controllers/MarvelController.java
import com.mpalourdio.springboottemplate.mediatype.MediaType;
import com.mpalourdio.springboottemplate.properties.MarvelProperties;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.util.Arrays;

/*
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package com.mpalourdio.springboottemplate.controllers;



@RestController
@RequestMapping("/marvel")
@EnableConfigurationProperties(MarvelProperties.class)
public class MarvelController {

    private final MarvelProperties marvelProperties;
    private final HttpHeaders addonHeaders = new HttpHeaders();

    public MarvelController(MarvelProperties marvelProperties) {
        this.marvelProperties = marvelProperties;
        buildAddonsHeaders(marvelProperties);
    }

    private void buildAddonsHeaders(MarvelProperties marvelProperties) {
        var unkownProperty = marvelProperties.getUnknownProperty();

        if (StringUtils.isNotBlank(unkownProperty)) {
            Arrays.asList(unkownProperty.split(",")).forEach(h -> {
                var split = h.split("=");
                addonHeaders.add(split[0], split[1]);
            });
        }
    }

    @GetMapping(value = "/all", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<String> allCharacters() {
        var restTemplate = new RestTemplate();
        var timestamp = String.valueOf(System.currentTimeMillis() / 1000);
        var hash = DigestUtils.md5Hex(timestamp + marvelProperties.getPrivatekey() + marvelProperties.getPublickey());
        var uri = "http://gateway.marvel.com/v1/public/characters/1009220?apikey="
                + marvelProperties.getPublickey()