// Path: src/main/java/se/bjurr/gitchangelog/api/exceptions/GitChangelogIntegrationException.java
// public class GitChangelogIntegrationException extends Exception {
// 
//   private static final long serialVersionUID = 4249741847365803709L;
// 
//   public GitChangelogIntegrationException(String message, Throwable throwable) {
//     super(message, throwable);
//   }
// 
//   public GitChangelogIntegrationException(String message) {
//     super(message);
//   }
// }


import static com.jayway.jsonpath.JsonPath.read;
import java.util.Map;
import java.util.Optional;
import se.bjurr.gitchangelog.api.exceptions.GitChangelogIntegrationException;
  }

  protected String getEndpoint(final String issue) {
    final String issueNo = getIssueNumber(issue);
    final String endpoint = this.api + "/issues/" + issueNo + ".json";
    return endpoint;
  }

  protected RedmineIssue toRedmineIssue(final String issue, final String json) {
    final String issueNo = getIssueNumber(issue);
    final String title = read(json, "$.issue.subject");
    final String description = read(json, "$.issue.description");
    final String type = read(json, "$.issue.tracker.name");
    final String link = this.api + "/issues/" + issueNo;

    final RedmineIssue redmineIssue = new RedmineIssue(title, description, link, issue, type);
    return redmineIssue;
  }

  protected String getIssueNumber(String issue) {
    return issue.startsWith("#") ? issue.substring(1) : issue;
  }

  public abstract RedmineClient withBasicCredentials(String username, String password);

  public abstract RedmineClient withTokenCredentials(String token);

  public abstract RedmineClient withHeaders(Map<String, String> headers);

  public abstract Optional<RedmineIssue> getIssue(String matched)
// Path: src/main/java/se/bjurr/gitchangelog/api/exceptions/GitChangelogIntegrationException.java
// public class GitChangelogIntegrationException extends Exception {
// 
//   private static final long serialVersionUID = 4249741847365803709L;
// 
//   public GitChangelogIntegrationException(String message, Throwable throwable) {
//     super(message, throwable);
//   }
// 
//   public GitChangelogIntegrationException(String message) {
//     super(message);
//   }
// }


// Path: src/main/java/se/bjurr/gitchangelog/internal/integrations/redmine/RedmineClient.java
import static com.jayway.jsonpath.JsonPath.read;
import java.util.Map;
import java.util.Optional;
import se.bjurr.gitchangelog.api.exceptions.GitChangelogIntegrationException;

  }

  protected String getEndpoint(final String issue) {
    final String issueNo = getIssueNumber(issue);
    final String endpoint = this.api + "/issues/" + issueNo + ".json";
    return endpoint;
  }

  protected RedmineIssue toRedmineIssue(final String issue, final String json) {
    final String issueNo = getIssueNumber(issue);
    final String title = read(json, "$.issue.subject");
    final String description = read(json, "$.issue.description");
    final String type = read(json, "$.issue.tracker.name");
    final String link = this.api + "/issues/" + issueNo;

    final RedmineIssue redmineIssue = new RedmineIssue(title, description, link, issue, type);
    return redmineIssue;
  }

  protected String getIssueNumber(String issue) {
    return issue.startsWith("#") ? issue.substring(1) : issue;
  }

  public abstract RedmineClient withBasicCredentials(String username, String password);

  public abstract RedmineClient withTokenCredentials(String token);

  public abstract RedmineClient withHeaders(Map<String, String> headers);

  public abstract Optional<RedmineIssue> getIssue(String matched)
      throws GitChangelogIntegrationException;