<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>xyz.tcheeric</groupId>
        <artifactId>gateway-plugin</artifactId>
        <version>0.8.0</version>
    </parent>

    <artifactId>gateway-it</artifactId>
    <name>Gateway Integration Tests</name>
    <description>Integration tests for the Cashu Gateway API using Testcontainers</description>

    <properties>
        <!-- Test execution controlled by parent profile properties -->

        <!-- Nostr Relay Testcontainer configuration -->
        <!-- Note: nostr.relay.port is the internal container port, Testcontainers maps to random external port -->
        <nostr.relay.image>dockurr/strfry</nostr.relay.image>
        <nostr.relay.tag>latest</nostr.relay.tag>
        <nostr.relay.port>8080</nostr.relay.port>

        <!-- nsecBunkerd Testcontainer configuration -->
        <!-- Disabled: nsecbunkerd has hardcoded relay URLs, needs config file mount to use local relay -->
        <nsecbunkerd.enabled>false</nsecbunkerd.enabled>
        <nsecbunkerd.image>docker.398ja.xyz/nsecbunkerd</nsecbunkerd.image>
        <nsecbunkerd.tag>latest</nsecbunkerd.tag>
        <nsecbunkerd.port>3000</nsecbunkerd.port>
    </properties>

    <dependencies>
        <!-- Gateway modules under test -->
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>gateway-app</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
            <exclusions>
                <!-- Exclude slf4j-simple to avoid conflict with Logback -->
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-simple</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Nostr integration for voucher backup tests (Phase 5.8) -->
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>wallet-core-nostr</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
            <exclusions>
                <!-- Exclude slf4j-simple to avoid conflict with Logback -->
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-simple</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>wallet-core-app</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
            <exclusions>
                <!-- Exclude slf4j-simple to avoid conflict with Logback -->
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-simple</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>wallet-nip-44</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>wallet-nip-60</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>gateway-rest</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
            <exclusions>
                <!-- Exclude slf4j-simple to avoid conflict with Logback -->
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-simple</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>gateway-api</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
            <exclusions>
                <!-- Exclude slf4j-simple to avoid conflict with Logback -->
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-simple</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>gateway-security</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
            <exclusions>
                <!-- Exclude slf4j-simple to avoid conflict with Logback -->
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-simple</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Spring Boot Test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- JUnit 5 -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-suite</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- AssertJ -->
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- Testcontainers -->
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>testcontainers</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>postgresql</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- WireMock for webhook testing -->
        <dependency>
            <groupId>org.wiremock</groupId>
            <artifactId>wiremock-standalone</artifactId>
            <version>${wiremock.version}</version>
            <scope>test</scope>
        </dependency>

        <!-- Awaitility for async testing -->
        <dependency>
            <groupId>org.awaitility</groupId>
            <artifactId>awaitility</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- REST Assured for API testing -->
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>5.5.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>json-path</artifactId>
            <version>5.5.0</version>
            <scope>test</scope>
        </dependency>

        <!-- Jackson -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
        </dependency>

        <!-- Logging -->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- Surefire for unit tests (also runs IT tests via mvn test) -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <additionalClasspathElements>
                        <!-- Ensure locally built gateway-rest classes (including TokenDmTransferAdapter) are available without installing to ~/.m2 -->
                        <additionalClasspathElement>${project.basedir}/../gateway-rest/target/classes</additionalClasspathElement>
                    </additionalClasspathElements>
                    <environmentVariables>
                        <!-- Nostr relay configuration -->
                        <NOSTR_RELAY_IMAGE>${nostr.relay.image}</NOSTR_RELAY_IMAGE>
                        <NOSTR_RELAY_TAG>${nostr.relay.tag}</NOSTR_RELAY_TAG>
                        <NOSTR_RELAY_PORT>${nostr.relay.port}</NOSTR_RELAY_PORT>
                        <!-- nsecBunkerd configuration -->
                        <NSECBUNKERD_ENABLED>${nsecbunkerd.enabled}</NSECBUNKERD_ENABLED>
                        <NSECBUNKERD_IMAGE>${nsecbunkerd.image}</NSECBUNKERD_IMAGE>
                        <NSECBUNKERD_TAG>${nsecbunkerd.tag}</NSECBUNKERD_TAG>
                        <NSECBUNKERD_PORT>${nsecbunkerd.port}</NSECBUNKERD_PORT>
                    </environmentVariables>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${maven.failsafe.plugin.version}</version>
                <configuration>
                    <!-- Uses skipITs.gateway from parent profiles -->
                    <skipITs>${skipITs.gateway}</skipITs>
                    <includes>
                        <include>**/*IT.java</include>
                        <include>**/*ITCase.java</include>
                        <include>**/*IntegrationTest.java</include>
                    </includes>
                    <!-- Uses it.groups from parent profiles if set -->
                    <groups>${it.groups}</groups>
                    <!-- Pass Testcontainer configuration as environment variables -->
                    <environmentVariables>
                        <!-- Nostr relay configuration -->
                        <NOSTR_RELAY_IMAGE>${nostr.relay.image}</NOSTR_RELAY_IMAGE>
                        <NOSTR_RELAY_TAG>${nostr.relay.tag}</NOSTR_RELAY_TAG>
                        <NOSTR_RELAY_PORT>${nostr.relay.port}</NOSTR_RELAY_PORT>
                        <!-- nsecBunkerd configuration -->
                        <NSECBUNKERD_ENABLED>${nsecbunkerd.enabled}</NSECBUNKERD_ENABLED>
                        <NSECBUNKERD_IMAGE>${nsecbunkerd.image}</NSECBUNKERD_IMAGE>
                        <NSECBUNKERD_TAG>${nsecbunkerd.tag}</NSECBUNKERD_TAG>
                        <NSECBUNKERD_PORT>${nsecbunkerd.port}</NSECBUNKERD_PORT>
                    </environmentVariables>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <!--
         Integration test profiles are centralized in parent POM.
         Use: mvn verify -Pit-gateway (all gateway integration tests)
         Use: mvn verify -Pit-all (all integration tests across repository)
    -->

</project>
