// Path: src/main/java/io/chucknorris/lib/mailchimp/MailchimpService.java
// public class MailchimpService {
// 
//   private String apiKey;
//   private String baseUrl;
// 
//   @Autowired
//   private RestTemplate restTemplate;
// 
//   public MailchimpService(String apiKey, String baseUrl) {
//     this.apiKey = apiKey;
//     this.baseUrl = baseUrl;
//   }
// 
//   /**
//    * Fetch mailing list stats by a given list id.
//    *
//    * @param listId The list id
//    * @return list
//    */
//   public MailingListStatistic fetchListStats(final String listId) {
//     return fetchList(listId).getMailingListStatistic();
//   }
// 
//   private MailingList fetchList(final String listId) {
//     HttpHeaders headers = new HttpHeaders();
//     headers.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
//     headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
//     headers.add(HttpHeaders.AUTHORIZATION, "apikey " + this.apiKey);
// 
//     ResponseEntity<MailingList> responseEntity = restTemplate.exchange(
//         baseUrl + "/3.0/lists/" + listId,
//         HttpMethod.GET,
//         new HttpEntity<>(null, headers),
//         MailingList.class
//     );
// 
//     return responseEntity.getBody();
//   }
// }


import io.chucknorris.lib.mailchimp.MailchimpService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
package io.chucknorris.api.configuration;


@Configuration
public class MailchimpConfig {

  @Value("${mailchimp.api_key}")
  private String apiKey;

  /**
   * Returns a new {@link MailchimpService} instance.
   */
  public @Bean MailchimpService mailchimpService() {
    String dataCenter = apiKey.substring(
        apiKey.length() - 4
    );
    String baseUrl = "https://" + dataCenter + ".api.mailchimp.com";

// Path: src/main/java/io/chucknorris/lib/mailchimp/MailchimpService.java
// public class MailchimpService {
// 
//   private String apiKey;
//   private String baseUrl;
// 
//   @Autowired
//   private RestTemplate restTemplate;
// 
//   public MailchimpService(String apiKey, String baseUrl) {
//     this.apiKey = apiKey;
//     this.baseUrl = baseUrl;
//   }
// 
//   /**
//    * Fetch mailing list stats by a given list id.
//    *
//    * @param listId The list id
//    * @return list
//    */
//   public MailingListStatistic fetchListStats(final String listId) {
//     return fetchList(listId).getMailingListStatistic();
//   }
// 
//   private MailingList fetchList(final String listId) {
//     HttpHeaders headers = new HttpHeaders();
//     headers.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
//     headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
//     headers.add(HttpHeaders.AUTHORIZATION, "apikey " + this.apiKey);
// 
//     ResponseEntity<MailingList> responseEntity = restTemplate.exchange(
//         baseUrl + "/3.0/lists/" + listId,
//         HttpMethod.GET,
//         new HttpEntity<>(null, headers),
//         MailingList.class
//     );
// 
//     return responseEntity.getBody();
//   }
// }


// Path: src/main/java/io/chucknorris/api/configuration/MailchimpConfig.java
import io.chucknorris.lib.mailchimp.MailchimpService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

package io.chucknorris.api.configuration;


@Configuration
public class MailchimpConfig {

  @Value("${mailchimp.api_key}")
  private String apiKey;

  /**
   * Returns a new {@link MailchimpService} instance.
   */
  public @Bean MailchimpService mailchimpService() {
    String dataCenter = apiKey.substring(
        apiKey.length() - 4
    );
    String baseUrl = "https://" + dataCenter + ".api.mailchimp.com";

    return new MailchimpService(apiKey, baseUrl);