// Path: src/main/java/com/frameworkium/core/api/tests/BaseAPITest.java
// @Listeners({MethodInterceptor.class,
//     TestListener.class,
//     ResultLoggerListener.class})
// @Test(groups = "base-api")
// public abstract class BaseAPITest {
// 
//   protected final Logger logger = LogManager.getLogger(this);
// 
//   /**
//    * Creates the allure properties for the report, after the test run.
//    */
//   @AfterSuite(alwaysRun = true)
//   public static void createAllureProperties() {
//     AllureProperties.createAPI();
//   }
// 
// }
// 
// Path: src/test/java/com/frameworkium/integration/capture/api/dto/screenshots/CreateScreenshot.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public class CreateScreenshot extends AbstractDTO<CreateScreenshot> {
// 
//     public Command command;
//     public String url;
//     public String executionID;
//     public String errorMessage;
//     public String screenshotBase64;
// 
//     public static CreateScreenshot newInstance(String executionID) {
//         CreateScreenshot createScreenshot = new CreateScreenshot();
//         createScreenshot.executionID = executionID;
//         createScreenshot.command = Command.newInstance();
//         createScreenshot.url = "http://test.url/hello?x=1&y=2";
//         createScreenshot.errorMessage = null;
//         createScreenshot.screenshotBase64 = getBase64TestImage();
//         return createScreenshot;
//     }
// 
//     private static String getBase64TestImage() {
//         try {
//             InputStream imageStream = CreateScreenshot.class.getClassLoader()
//                     .getResourceAsStream("capture-screenshot.png");
//             byte[] bytes = IOUtils.toByteArray(imageStream);
//             return Base64.getEncoder().encodeToString(bytes);
//         } catch (IOException e) {
//             throw new IllegalStateException(e);
//         }
//     }
// }
// 
// Path: src/test/java/com/frameworkium/integration/capture/api/dto/screenshots/Screenshot.java
// public class Screenshot extends AbstractDTO<Screenshot> {
// 
//     public Command command;
//     public String imageURL;
//     public String timestamp;
//     public String url;
// 
// }
// 
// Path: src/test/java/com/frameworkium/integration/capture/api/service/executions/ExecutionService.java
// public class ExecutionService extends BaseCaptureService {
// 
//     @Step("Create Capture Execution {createMessage}")
//     public ExecutionID createExecution(CreateExecution createMessage) {
//         return post(CaptureEndpoint.EXECUTIONS.getUrl(), createMessage)
//                 .extract()
//                 .as(ExecutionID.class);
//     }
// 
//     @Step("Get Capture Executions, page={page}, pageSize={pageSize}")
//     public ExecutionResults getExecutions(int page, int pageSize) {
//         return get(
//                 ImmutableMap.of("page", page, "pageSize", pageSize),
//                 CaptureEndpoint.EXECUTIONS.getUrl())
//                 .as(ExecutionResults.class);
//     }
// 
//     public ExecutionResponse getExecution(String executionID) {
//         return get(CaptureEndpoint.GET_EXECUTION.getUrl(executionID))
//                 .as(ExecutionResponse.class);
//     }
// }
// 
// Path: src/test/java/com/frameworkium/integration/capture/api/service/screenshots/ScreenshotService.java
// public class ScreenshotService extends BaseCaptureService {
// 
//     public void createScreenshot(CreateScreenshot createMessage) {
//         post(CaptureEndpoint.SCREENSHOT.getUrl(), createMessage);
//     }
// 
// }


import com.frameworkium.core.api.tests.BaseAPITest;
import com.frameworkium.integration.capture.api.dto.executions.*;
import com.frameworkium.integration.capture.api.dto.screenshots.CreateScreenshot;
import com.frameworkium.integration.capture.api.dto.screenshots.Screenshot;
import com.frameworkium.integration.capture.api.service.executions.ExecutionService;
import com.frameworkium.integration.capture.api.service.screenshots.ScreenshotService;
import org.openqa.selenium.NotFoundException;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Ignore;
import org.testng.annotations.Test;
import java.util.List;
import java.util.stream.Collectors;
import static com.google.common.truth.Truth.assertThat;

        List<ExecutionResponse> filteredExecutions =
                latestExecutions
                        .results.stream()
                        .filter(ex -> executionID.equals(ex.executionID))
                        .collect(Collectors.toList());

        // ensure only one with our expected ID
        assertThat(filteredExecutions).hasSize(1);

        ExecutionResponse response = filteredExecutions.get(0);
        assertThat(response.createdFrom(createExMessage)).isTrue();
    }

    @Test
    public void new_execution_has_status_new_and_last_updated_equals_created() {
        String id = new ExecutionService()
                .createExecution(createExMessage)
                .executionID;
        ExecutionResponse execution = new ExecutionService()
                .getExecutions(1, 20)
                .results.stream()
                .filter(ex -> id.equals(ex.executionID))
                .findFirst().orElseThrow(NotFoundException::new);
        assertThat(execution.currentStatus).isEqualTo("new");
        assertThat(execution.lastUpdated).isEqualTo(execution.created);
    }

    @Test
    public void can_add_then_view_screenshot() {
// Path: src/main/java/com/frameworkium/core/api/tests/BaseAPITest.java
// @Listeners({MethodInterceptor.class,
//     TestListener.class,
//     ResultLoggerListener.class})
// @Test(groups = "base-api")
// public abstract class BaseAPITest {
// 
//   protected final Logger logger = LogManager.getLogger(this);
// 
//   /**
//    * Creates the allure properties for the report, after the test run.
//    */
//   @AfterSuite(alwaysRun = true)
//   public static void createAllureProperties() {
//     AllureProperties.createAPI();
//   }
// 
// }
// 
// Path: src/test/java/com/frameworkium/integration/capture/api/dto/screenshots/CreateScreenshot.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public class CreateScreenshot extends AbstractDTO<CreateScreenshot> {
// 
//     public Command command;
//     public String url;
//     public String executionID;
//     public String errorMessage;
//     public String screenshotBase64;
// 
//     public static CreateScreenshot newInstance(String executionID) {
//         CreateScreenshot createScreenshot = new CreateScreenshot();
//         createScreenshot.executionID = executionID;
//         createScreenshot.command = Command.newInstance();
//         createScreenshot.url = "http://test.url/hello?x=1&y=2";
//         createScreenshot.errorMessage = null;
//         createScreenshot.screenshotBase64 = getBase64TestImage();
//         return createScreenshot;
//     }
// 
//     private static String getBase64TestImage() {
//         try {
//             InputStream imageStream = CreateScreenshot.class.getClassLoader()
//                     .getResourceAsStream("capture-screenshot.png");
//             byte[] bytes = IOUtils.toByteArray(imageStream);
//             return Base64.getEncoder().encodeToString(bytes);
//         } catch (IOException e) {
//             throw new IllegalStateException(e);
//         }
//     }
// }
// 
// Path: src/test/java/com/frameworkium/integration/capture/api/dto/screenshots/Screenshot.java
// public class Screenshot extends AbstractDTO<Screenshot> {
// 
//     public Command command;
//     public String imageURL;
//     public String timestamp;
//     public String url;
// 
// }
// 
// Path: src/test/java/com/frameworkium/integration/capture/api/service/executions/ExecutionService.java
// public class ExecutionService extends BaseCaptureService {
// 
//     @Step("Create Capture Execution {createMessage}")
//     public ExecutionID createExecution(CreateExecution createMessage) {
//         return post(CaptureEndpoint.EXECUTIONS.getUrl(), createMessage)
//                 .extract()
//                 .as(ExecutionID.class);
//     }
// 
//     @Step("Get Capture Executions, page={page}, pageSize={pageSize}")
//     public ExecutionResults getExecutions(int page, int pageSize) {
//         return get(
//                 ImmutableMap.of("page", page, "pageSize", pageSize),
//                 CaptureEndpoint.EXECUTIONS.getUrl())
//                 .as(ExecutionResults.class);
//     }
// 
//     public ExecutionResponse getExecution(String executionID) {
//         return get(CaptureEndpoint.GET_EXECUTION.getUrl(executionID))
//                 .as(ExecutionResponse.class);
//     }
// }
// 
// Path: src/test/java/com/frameworkium/integration/capture/api/service/screenshots/ScreenshotService.java
// public class ScreenshotService extends BaseCaptureService {
// 
//     public void createScreenshot(CreateScreenshot createMessage) {
//         post(CaptureEndpoint.SCREENSHOT.getUrl(), createMessage);
//     }
// 
// }


// Path: src/test/java/com/frameworkium/integration/capture/api/tests/CaptureExecutionAPITest.java
import com.frameworkium.core.api.tests.BaseAPITest;
import com.frameworkium.integration.capture.api.dto.executions.*;
import com.frameworkium.integration.capture.api.dto.screenshots.CreateScreenshot;
import com.frameworkium.integration.capture.api.dto.screenshots.Screenshot;
import com.frameworkium.integration.capture.api.service.executions.ExecutionService;
import com.frameworkium.integration.capture.api.service.screenshots.ScreenshotService;
import org.openqa.selenium.NotFoundException;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Ignore;
import org.testng.annotations.Test;
import java.util.List;
import java.util.stream.Collectors;
import static com.google.common.truth.Truth.assertThat;


        List<ExecutionResponse> filteredExecutions =
                latestExecutions
                        .results.stream()
                        .filter(ex -> executionID.equals(ex.executionID))
                        .collect(Collectors.toList());

        // ensure only one with our expected ID
        assertThat(filteredExecutions).hasSize(1);

        ExecutionResponse response = filteredExecutions.get(0);
        assertThat(response.createdFrom(createExMessage)).isTrue();
    }

    @Test
    public void new_execution_has_status_new_and_last_updated_equals_created() {
        String id = new ExecutionService()
                .createExecution(createExMessage)
                .executionID;
        ExecutionResponse execution = new ExecutionService()
                .getExecutions(1, 20)
                .results.stream()
                .filter(ex -> id.equals(ex.executionID))
                .findFirst().orElseThrow(NotFoundException::new);
        assertThat(execution.currentStatus).isEqualTo("new");
        assertThat(execution.lastUpdated).isEqualTo(execution.created);
    }

    @Test
    public void can_add_then_view_screenshot() {
        CreateScreenshot createScreenshot = CreateScreenshot.newInstance(executionID);