<?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>wallet-plugin</artifactId>
        <version>1.2.5</version>
    </parent>

    <artifactId>wallet-cli</artifactId>
    <name>cashu-client CLI</name>
    <properties>
        <maven.compiler.source>21</maven.compiler.source>
        <maven.compiler.target>21</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <shade.skip>false</shade.skip>
    </properties>

    <dependencies>
        <!-- Phase 7.1.1: CLI uses wallet-core-app + identity-plugin -->
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>wallet-core-app</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>identity-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>identity-application</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>identity-infrastructure</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>wallet-nip-04</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>wallet-nip-44</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>wallet-nip-42</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>cashu-lib-common</artifactId>

        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>bip-utils</artifactId>
            <version>${bip-utils.version}</version>
            <exclusions>
                <!-- Exclude slf4j-simple to use logback for MDC support in tests -->
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-simple</artifactId>
                </exclusion>
                <!-- Exclude old BouncyCastle to avoid version conflict with bcprov-jdk18on:1.81 -->
                <exclusion>
                    <groupId>org.bouncycastle</groupId>
                    <artifactId>bcprov-jdk15to18</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>cashu-wallet-client</artifactId>
            <version>${cashu.wallet.client.explicit}</version>
            <exclusions>
                <exclusion>
                    <groupId>xyz.tcheeric</groupId>
                    <artifactId>cashu-wallet-protocol</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- Explicitly use cashu-wallet-protocol 0.1.4 for NUT-09 /restore support -->
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>cashu-wallet-protocol</artifactId>
            <version>${cashu.wallet.protocol.explicit}</version>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>wallet-storage-file</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>wallet-storage-h2</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>info.picocli</groupId>
            <artifactId>picocli</artifactId>
        </dependency>
        <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>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>testcontainers</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </dependency>
        <dependency>
            <groupId>net.logstash.logback</groupId>
            <artifactId>logstash-logback-encoder</artifactId>
        </dependency>
        <dependency>
            <groupId>org.codehaus.janino</groupId>
            <artifactId>janino</artifactId>
        </dependency>
        <!-- OpenTelemetry API (for CLI integration) -->
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-api</artifactId>
        </dependency>
    </dependencies>

    <build>
        <testResources>
            <testResource>
                <directory>${project.basedir}/src/test/resources</directory>
            </testResource>
            <testResource>
                <directory>${project.basedir}/../../fixtures/localstack</directory>
            </testResource>
            <testResource>
                <directory>${project.basedir}/../wallet-core/wallet-core-nostr/src/test/resources</directory>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <!-- Exclude integration tests from default test phase -->
                    <excludedGroups>integration</excludedGroups>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>xyz.tcheeric.wallet.cli.WalletMain</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>${maven.shade.plugin.version}</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <skip>${shade.skip}</skip>
                            <!-- Disable minimization - wallet-core requires full Spring ecosystem -->
                            <minimizeJar>false</minimizeJar>
                            <!-- Note: BouncyCastle is now included in shaded JAR. Signature files are excluded via filters. -->
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>xyz.tcheeric.wallet.cli.WalletMain</mainClass>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                            </transformers>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                        <exclude>META-INF/versions/**</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>prepare-unsigned-bouncycastle</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <mkdir dir="${project.build.directory}/test-lib"/>
                                <zip destfile="${project.build.directory}/test-lib/bcprov-unsigned.jar">
                                    <zipfileset src="${settings.localRepository}/org/bouncycastle/bcprov-jdk18on/1.81/bcprov-jdk18on-1.81.jar">
                                        <exclude name="META-INF/*.SF"/>
                                        <exclude name="META-INF/*.DSA"/>
                                        <exclude name="META-INF/*.RSA"/>
                                    </zipfileset>
                                </zip>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${maven.failsafe.plugin.version}</version>
                <configuration>
                    <!-- Uses skipITs.wallet from parent profiles -->
                    <skipITs>${skipITs.wallet}</skipITs>
                    <argLine>@{argLine}</argLine>
                    <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>
                    <systemPropertyVariables>
                        <testcontainers.reuse.enable>true</testcontainers.reuse.enable>
                        <wallet.relay.circuitBreaker.failureRateThreshold>25</wallet.relay.circuitBreaker.failureRateThreshold>
                        <wallet.relay.circuitBreaker.windowType>COUNT</wallet.relay.circuitBreaker.windowType>
                        <wallet.relay.circuitBreaker.windowSize>4</wallet.relay.circuitBreaker.windowSize>
                        <wallet.relay.circuitBreaker.minimumCalls>2</wallet.relay.circuitBreaker.minimumCalls>
                        <wallet.relay.circuitBreaker.openWaitMs>200</wallet.relay.circuitBreaker.openWaitMs>
                        <wallet.relay.circuitBreaker.permittedHalfOpen>1</wallet.relay.circuitBreaker.permittedHalfOpen>
                        <WALLET_HOME>/tmp/.cashu-client-tests</WALLET_HOME>
                        <CASHU_HOME>/tmp/.cashu-client-tests</CASHU_HOME>
                    </systemPropertyVariables>
                    <classpathDependencyExcludes>
                        <classpathDependencyExclude>org.bouncycastle:bcprov-jdk18on</classpathDependencyExclude>
                    </classpathDependencyExcludes>
                    <additionalClasspathElements>
                        <additionalClasspathElement>${project.build.directory}/test-lib/bcprov-unsigned.jar</additionalClasspathElement>
                    </additionalClasspathElements>
                    <environmentVariables>
                        <WALLET_HOME>/tmp/.cashu-client-tests</WALLET_HOME>
                        <CASHU_HOME>/tmp/.cashu-client-tests</CASHU_HOME>
                    </environmentVariables>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>no-shade</id>
            <properties>
                <shade.skip>true</shade.skip>
            </properties>
        </profile>
    </profiles>

    <!--
         Integration test execution is controlled by parent profile properties.
         Use: mvn verify -Pit-wallet-cli (wallet CLI integration tests)
         Use: mvn verify -Pit-wallet (all wallet integration tests)
         Use: mvn verify -Pit-all (all integration tests across repository)

         Failsafe plugin is configured in build section for consistent inclusion,
         skip behavior is controlled via skipITs.wallet property from parent.
    -->

</project>
