public class AuthExpiredException extends Exception {

    /**
     *
     */
    private static final long serialVersionUID = 1L;

    public AuthExpiredException() {
        super("Authentication Expired. Need to login again.");
    }
} public class CommandException extends Exception {

    /**
     *
     */
    private static final long serialVersionUID = -2201560758494317755L;

    public CommandException(String errorMessage) {
        super(errorMessage);
    }
} public class RateLimitException extends Exception {
    /**
     *
     */
    private static final long serialVersionUID = 1L;

    public RateLimitException() {
        super("Too many requests. Please wait before calling again.");
    }
} public class UnderMaintenanceException extends Exception {

    /**
     *
     */
    private static final long serialVersionUID = 1L;

    public UnderMaintenanceException() {
        super("Copyleaks is Under Maintenance, please visit https://status.copyleaks.com");
    }
} public class CopyleaksExportModel {
    /**
     * @param completionWebhook This webhook event is triggered once the export is completed.
     * @param results An array of results to be exported. The equivalent of downloading results manually.
     * @param crawledVersion Download the crawled version of the submitted text. The equivalent of downloading crawled version manually.
     * @param maxRetries How many retries to send before giving up. Using high value (12) may lead to a longer time until the completionWebhook being executed. A low value (1) may lead to errors while your service is temporary having problems.
     * @param developerPayload Add a custom developer payload that will then be provided on the Export-Completed webhook. https://api.copyleaks.com/documentation/v3/webhooks/export-completed
     * @param pdfReport Download the PDF report. Allowed only when `properties.pdf.create` was set to true on the scan submittion.
     */
    private String completionWebhook;
    private ExportResults[] results;
    private ExportCrawledVersion crawledVersion;
    private Integer maxRetries = null;
    private String developerPayload = null;
    private ExportPdfReport pdfReport = null;

    public CopyleaksExportModel(String completionWebhook, ExportResults[] results, ExportCrawledVersion crawledVersion) {
        this.completionWebhook = completionWebhook;
        this.results = results;
        this.crawledVersion = crawledVersion;
    }

    public String getCompletionWebhook() {
        return completionWebhook;
    }

    public void setCompletionWebhook(String completionWebhook) {
        this.completionWebhook = completionWebhook;
    }

    public ExportResults[] getResults() {
        return results;
    }

    public ExportCrawledVersion getCrawledVersion() {
        return crawledVersion;
    }

    public Integer getMaxRetries() {
        return maxRetries;
    }

    public void setMaxRetries(Integer maxRetries) {
        this.maxRetries = maxRetries;
    }

    public String getDeveloperPayload() {
        return developerPayload;
    }

    public void setDeveloperPayload(String developerPayload) {
        this.developerPayload = developerPayload;
    }

    public ExportPdfReport getPdfReport() {
        return pdfReport;
    }

    public void setPdfReport(ExportPdfReport pdfReport) {
        this.pdfReport = pdfReport;
    }
} public class CopyleaksDeleteRequest {

    /**
     * @param scans The list of scans to delete
     * @param purge Delete all trace of the scan from Copyleaks server, including from internal database. A purged process will not be available as a result for previous scans.
     * @param completionWebhook Allows you to register to a webhook that will be fired once the removal has been completed. Make sure that your endpoint is listening to a POST method (no body parameters were supplied).
     */

    private ScansRequests[] scans;
    private boolean purge;
    private String uri;

    public CopyleaksDeleteRequest(ScansRequests[] scans, boolean purge, String uri) {
        this.scans = scans;
        this.purge = purge;
        this.uri = uri;
    }

    public ScansRequests[] getScans() {
        return scans;
    }

    public boolean isPurge() {
        return purge;
    }

    public String getUri() {
        return uri;
    }

} public class CopyleaksStartRequest {

    private String[] trigger;
    private int errorHandling;

    /**
     * @param trigger       A list of scans that you submitted for a check-credits scan and that you would like to submit for a full scan.
     * @param errorHandling When set to ignore (ignore = 1) the trigger scans will start running even if some of them are in error mode, when set to cancel (cancel = 0) the request will be cancelled if any error was found.
     */
    public CopyleaksStartRequest(String[] trigger, int errorHandling) {
        this.trigger = trigger;
        this.errorHandling = errorHandling;
    }

    public String[] getTrigger() {
        return trigger;
    }

    public int getErrorHandling() {
        return errorHandling;
    }
} public class CopyleaksFileOcrSubmissionModel extends CopyleaksFileSubmissionModel {
    /**
     * @param langCode The language code of your content. The selected language should be on the OCR supported languages list. https://api.copyleaks.com/documentation/v3/specifications/ocr-languages
     * @param base64 A base64 data string of a file. If you would like to scan plain text, encode it as base64 and submit it.
     * @param filename The name of the file as it will appear in the Copyleaks scan report Make sure to include the right extension for your filetype.
     * @param properties Check inner properties for more details.
     */
    private String langCode;

    public CopyleaksFileOcrSubmissionModel(String langCode, String base64, String filename, SubmissionProperties properties) {
        super(base64, filename, properties);
        this.langCode = langCode;
    }
} public class CopyleaksFileSubmissionModel extends CopyleaksSubmissionModel {
    /**
     * @param base64 A base64 data string of a file. If you would like to scan plain text, encode it as base64 and submit it.
     * @param filename The name of the file as it will appear in the Copyleaks scan report Make sure to include the right extension for your filetype.
     * @param properties Check inner properties for more details.
     */
    private String base64;
    private String filename;

    public CopyleaksFileSubmissionModel(String base64, String filename, SubmissionProperties properties) {
        super(properties);
        this.base64 = base64;
        this.filename = filename;
    }

    public String getBase64() {
        return base64;
    }

    public void setBase64(String base64) {
        this.base64 = base64;
    }

    public String getFilename() {
        return filename;
    }

    public void setFilename(String filename) {
        this.filename = filename;
    }
} public class CopyleaksURLSubmissionModel extends CopyleaksSubmissionModel {
    /**
     * @param url The url to be scanned
     * @param properties Check inner properties for more details.
     */
    private String url;

    public CopyleaksURLSubmissionModel(String url, SubmissionProperties properties) {
        super(properties);
        this.url = url;
    }
}
import com.google.gson.Gson;
import models.exceptions.AuthExpiredException;
import models.exceptions.CommandException;
import models.exceptions.RateLimitException;
import models.exceptions.UnderMaintenanceException;
import models.exports.CopyleaksExportModel;
import models.request.CopyleaksDeleteRequest;
import models.request.CopyleaksStartRequest;
import models.response.*;
import models.submissions.CopyleaksFileOcrSubmissionModel;
import models.submissions.CopyleaksFileSubmissionModel;
import models.submissions.CopyleaksURLSubmissionModel;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.text.ParseException;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
/*
 The MIT License(MIT)
 Copyright(c) 2016 Copyleaks LTD (https://copyleaks.com)
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:
 The above copyright notice and this permission notice shall be included in all
 copies or substantial portions of the Software.
 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 NON INFRINGEMENT. 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 classes;



public class Copyleaks {

    private static final HttpClient HTTP_CLIENT = HttpClient.newBuilder()
            .build();

    private static final Gson gson = new Gson();

    /**
     * Login to Copyleaks authentication server.
     * For more info: https://api.copyleaks.com/documentation/v3/account/login.
     * * Exceptions:
     * * CommandExceptions: Server reject the request. See response status code,
     * headers and content for more info.
     * * UnderMaintenanceException: Copyleaks servers are unavailable for maintenance.
     * We recommend to implement exponential backoff algorithm as described here:
     * https://api.copyleaks.com/documentation/v3/exponential-backoff
     *
     * @param email Copyleaks account email address.
     * @param key   Copyleaks account secret key.
     * @return CopyleaksAuthToken A authentication token that being expired after certain amount of time.
     * @throws ExecutionException, UnderMaintenanceException, RateLimitException, CommandException, InterruptedException
     */
    public static CopyleaksAuthToken login(String email, String key)
            throws ExecutionException, UnderMaintenanceException, RateLimitException, CommandException, InterruptedException {