<?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>imani-gateway-core</artifactId>
        <version>0.16.1</version>
    </parent>

    <artifactId>gateway-core-rest</artifactId>
    <packaging>jar</packaging>
    <name>Gateway Core - REST + Spring Boot Application</name>
    <description>REST controllers, Spring Boot application, and configuration for the Gateway Core service (account, identity, auth, config)</description>

    <dependencies>
        <!-- Shared libraries -->
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>imani-commons</artifactId>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>imani-security</artifactId>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>imani-gateway-api</artifactId>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>imani-nostrdb</artifactId>
        </dependency>

        <!-- Cashu libraries — needed for server-side voucher split + mint swap.
             See xyz.tcheeric.gateway.core.voucher and xyz.tcheeric.gateway.core.swap
             packages. Classes ported from imani-bridge/gateway-plugin/gateway-rest;
             keep the two copies in sync until a shared module is extracted. -->
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>wallet-core-cashu</artifactId>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>cashu-voucher-domain</artifactId>
        </dependency>

        <!-- Identity modules -->
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>identity-api</artifactId>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>identity-domain</artifactId>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>identity-application</artifactId>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>identity-infrastructure</artifactId>
        </dependency>

        <!-- NAP Java (Nostr Authentication Protocol) -->
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>nap-spring</artifactId>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>nap-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>nap-server</artifactId>
        </dependency>

        <!-- Spring Boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- Apache HttpClient 5 — backs the pooling HTTP connection manager
             we wire under lnbitsRestTemplate (spec 041 Phase 7 SC-002 work).
             Without it Spring falls back to JDK SimpleClientHttpRequestFactory
             which has NO connection pooling, opening a fresh TCP connection
             on every LNbits call. Under 50-VU load that fills the socket
             accept queue and drives initiate p95 into the 18s range. -->
        <dependency>
            <groupId>org.apache.httpcomponents.client5</groupId>
            <artifactId>httpclient5</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <!-- Spec 014 (payment receipts): durable, broker-backed delivery
             channel for sender blue-tick confirmations. Embedded ActiveMQ
             Artemis runs in-JVM; the journal is volume-mounted at deploy
             time (T068). See xyz.tcheeric.gateway.core.receipts package
             (added by T003) for the producer/consumer code. -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-artemis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>artemis-jakarta-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>artemis-jakarta-client</artifactId>
        </dependency>

        <!-- Spec 014 (payment receipts): JMS message records
             (PaymentReceiptIssuedEvent, PaymentReceiptDelivery,
             PaymentReceiptAck) live in the messaging-contracts artifact
             under xyz.tcheeric.messaging.messages.receipts. Version is
             managed by the parent pom (messaging-contracts.version). -->
        <dependency>
            <groupId>xyz.tcheeric</groupId>
            <artifactId>messaging-contracts</artifactId>
        </dependency>

        <!-- Spring Cache with Caffeine -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-cache</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.ben-manes.caffeine</groupId>
            <artifactId>caffeine</artifactId>
        </dependency>

        <!-- Database -->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-database-postgresql</artifactId>
        </dependency>

        <!-- Resilience4j — used by ResilientLNbitsClient + atomic-purchase saga
             retry/circuit-breaker/rate-limiter pipelines. Versions managed by
             imani-bom (resilience4j.version=2.1.0). Added 2026-04-12 as part
             of spec 003 FR-GCC-004 prep — required before the atomic saga
             Java code port (T044..T058) can compile. -->
        <dependency>
            <groupId>io.github.resilience4j</groupId>
            <artifactId>resilience4j-retry</artifactId>
        </dependency>
        <dependency>
            <groupId>io.github.resilience4j</groupId>
            <artifactId>resilience4j-circuitbreaker</artifactId>
        </dependency>
        <dependency>
            <groupId>io.github.resilience4j</groupId>
            <artifactId>resilience4j-ratelimiter</artifactId>
        </dependency>

        <!-- Distributed locking for @Scheduled jobs in multi-replica
             deployments (FR-GAP-010 from spec 002). Used by PurchaseRecoveryJob,
             SendRecoveryJob, and any future @Scheduled sweep in gateway-core.
             Version 5.16.0 hard-pinned here — imani-bom does not manage
             shedlock versions, so we mirror the atomic repo's pin. Added
             2026-04-12 as part of spec 003 FR-GCC-004 prep; required before
             the recovery-job port (T049) can compile. The actual lock
             table was already relocated as V19__shedlock.sql (T059). -->
        <dependency>
            <groupId>net.javacrumbs.shedlock</groupId>
            <artifactId>shedlock-spring</artifactId>
            <version>5.16.0</version>
        </dependency>
        <dependency>
            <groupId>net.javacrumbs.shedlock</groupId>
            <artifactId>shedlock-provider-jdbc-template</artifactId>
            <version>5.16.0</version>
        </dependency>

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

        <!-- BouncyCastle for Web Push encryption -->
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcprov-jdk18on</artifactId>
        </dependency>

        <!-- Observability: Micrometer Tracing with OpenTelemetry bridge -->
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-tracing-bridge-otel</artifactId>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-exporter-otlp</artifactId>
        </dependency>

        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>

        <!-- Testing -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- H2 in-memory DB for relocated atomic-operations unit tests
             (state machine, JDBC repositories). Matches atomic repo's
             test-scope dep. -->
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring-boot-maven-plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <classifier>exec</classifier>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>jib-maven-plugin</artifactId>
                <version>${jib-maven-plugin.version}</version>
                <configuration>
                    <from>
                        <image>eclipse-temurin:21-jre</image>
                    </from>
                    <to>
                        <image>docker.398ja.xyz/gateway-core</image>
                        <tags>
                            <tag>${project.version}</tag>
                            <tag>latest</tag>
                        </tags>
                    </to>
                    <container>
                        <ports>
                            <port>8081</port>
                        </ports>
                        <jvmFlags>
                            <jvmFlag>-Xms256m</jvmFlag>
                            <jvmFlag>-Xmx512m</jvmFlag>
                            <!-- BottinNip05Manager sets the Host header explicitly on
                                 /.well-known/nostr.json requests so bottin-web looks up
                                 NIP-05 records for the correct domain. Host is a
                                 restricted header by default in Java's HttpClient. -->
                            <jvmFlag>-Djdk.httpclient.allowRestrictedHeaders=host</jvmFlag>
                        </jvmFlags>
                    </container>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
