<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <artifactId>nvx-rumi-appbuilder-rest</artifactId>
    <packaging>jar</packaging>
    <name>Rumi App Builder REST Service</name>

    <parent>
        <groupId>com.neeve</groupId>
        <artifactId>nvx-rumi-appbuilder-parent</artifactId>
        <version>1.0.1</version>
    </parent>

    <properties>
        <jetty.version>12.0.16</jetty.version>
        <jersey.version>3.1.11</jersey.version>
        <jackson.version>2.18.2</jackson.version>
        <swagger.version>2.2.36</swagger.version>
        <slf4j.version>2.0.16</slf4j.version>
        <nvx.rumi.version>4.0.629</nvx.rumi.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.neeve</groupId>
            <artifactId>nvx-rumi-appbuilder-sdk</artifactId>
            <version>${project.version}</version>
        </dependency>

        <!-- Rumi Core (AEP, @EventHandler, @AppInjectionPoint, Config) -->
        <dependency>
            <groupId>com.neeve</groupId>
            <artifactId>nvx-rumi</artifactId>
            <version>${nvx.rumi.version}</version>
        </dependency>

        <!-- Canonical Java 11+ runtime deps per the Rumi docs
             (core/guides/developing-applications/set-up-your-dev-environment).
             Rumi core uses the legacy javax.xml.bind namespace for config
             parsing and expects these exact coordinates. Matches the
             Datafye Platform parent POM. -->
        <dependency>
            <groupId>javax.annotation</groupId>
            <artifactId>javax.annotation-api</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>jakarta.xml.bind</groupId>
            <artifactId>jakarta.xml.bind-api</artifactId>
            <version>2.3.2</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>2.3.2</version>
        </dependency>

        <!-- Jersey (Jakarta EE 10) -->
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-server</artifactId>
            <version>${jersey.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            <version>${jersey.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.inject</groupId>
            <artifactId>jersey-hk2</artifactId>
            <version>${jersey.version}</version>
        </dependency>
        <!-- Jersey's JSON-Jackson integration (jersey-media-json-jackson) is
             deliberately NOT used. It hardcodes a static reference to
             JakartaXmlBindAnnotationIntrospector, which forces jakarta.xml.bind
             4.x (jakarta namespace) on the classpath; that conflicts with the
             2.3.2 jars (javax namespace) Rumi core requires. We register a
             thin Jackson body reader/writer in Main.ResourceConfig instead. -->

        <!-- Jackson (explicit to pin the version matrix) -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>

        <!-- Jetty 12 (Jakarta EE 10) -->
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-server</artifactId>
            <version>${jetty.version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty.ee10</groupId>
            <artifactId>jetty-ee10-servlet</artifactId>
            <version>${jetty.version}</version>
        </dependency>

        <!-- Swagger annotations for @Tag / @Operation / @OpenAPIDefinition on
             resource classes. The full swagger-jaxrs2-jakarta lives only under
             the swagger-maven-plugin-jakarta's plugin classpath (see build)
             because it transitively pulls a jackson-jakarta-xmlbind chain
             that conflicts with Rumi core's javax.xml.bind. -->
        <dependency>
            <groupId>io.swagger.core.v3</groupId>
            <artifactId>swagger-annotations-jakarta</artifactId>
            <version>${swagger.version}</version>
        </dependency>

        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>${slf4j.version}</version>
            <scope>runtime</scope>
        </dependency>

        <!-- Test -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- REST module runs on a JVM we control; use Java 17 features.
                 The SDK stays at Java 11 for library-consumer compatibility. -->
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <release>17</release>
                </configuration>
            </plugin>

            <!-- Compile-time OpenAPI generation. Scans resource classes in
                 com.neeve.appbuilder.rest.resources, picks up the
                 @OpenAPIDefinition on AbstractResource for global metadata,
                 and emits META-INF/openAPI/appbuilder-api.yaml into the
                 classes output. SwaggerUI serves that file at runtime. -->
            <plugin>
                <groupId>io.swagger.core.v3</groupId>
                <artifactId>swagger-maven-plugin-jakarta</artifactId>
                <version>${swagger.version}</version>
                <dependencies>
                    <!-- Plugin-scope dep; NOT on the app's runtime classpath.
                         Keeps the jackson-jakarta-xmlbind chain out of the
                         shipped bin/java/lib/. -->
                    <dependency>
                        <groupId>io.swagger.core.v3</groupId>
                        <artifactId>swagger-jaxrs2-jakarta</artifactId>
                        <version>${swagger.version}</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <outputFileName>appbuilder-api</outputFileName>
                    <outputPath>${project.build.outputDirectory}/META-INF/openAPI</outputPath>
                    <outputFormat>YAML</outputFormat>
                    <scanDependencies>false</scanDependencies>
                    <resourcePackages>
                        <package>com.neeve.appbuilder.rest.resources</package>
                    </resourcePackages>
                    <prettyPrint>true</prettyPrint>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>resolve</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <!--
          'dist' profile: builds the standalone, sandbox-wrapped tarball
          for Mgmt-Agent-style install. Requires -Darch=<os-cpu> where
          <os-cpu> is one of linux-x86-64 | linux-arm-64 | osx-x86-64 |
          osx-arm-64 (matching the classifier convention of the Rumi
          sandbox distribution).

          Produces: target/nvx-rumi-appbuilder-rest-<version>-<arch>.tar.gz

          Activate with:
              mvn -Pdist -Darch=osx-arm-64 package
        -->
        <profile>
            <id>dist</id>
            <dependencies>
                <dependency>
                    <groupId>com.neeve</groupId>
                    <artifactId>nvx-rumi</artifactId>
                    <version>${nvx.rumi.version}</version>
                    <classifier>sandbox-${arch}</classifier>
                    <type>tar.gz</type>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <version>3.6.0</version>
                        <executions>
                            <execution>
                                <id>standalone</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                                <configuration>
                                    <descriptors>
                                        <descriptor>src/assembly/standalone.xml</descriptor>
                                    </descriptors>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
