<?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>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>4.1.0</version>
        <relativePath/>
    </parent>

    <groupId>net.thebennett.platform</groupId>
    <artifactId>platform-parent</artifactId>
    <version>0.1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>The Bennett Platform :: Parent</name>
    <description>Shared parent POM: Java/Spring versions, dependency and plugin management for all apps.</description>

    <properties>
        <java.version>25</java.version>
        <maven.compiler.release>25</maven.compiler.release>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <aws.sdk.version>2.39.6</aws.sdk.version>
        <!-- Frontend standard: Vite + React + TS SPA built into the jar. An app opts in by declaring
             the two managed plugins below; set -DskipFrontend=true for backend-only iterations. -->
        <node.version>v22.12.0</node.version>
        <skipFrontend>false</skipFrontend>
        <frontend-maven-plugin.version>1.15.1</frontend-maven-plugin.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <!-- AWS SDK v2 (S3 / MinIO) version alignment -->
            <dependency>
                <groupId>software.amazon.awssdk</groupId>
                <artifactId>bom</artifactId>
                <version>${aws.sdk.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <pluginManagement>
            <plugins>
                <!-- Standard SPA build: an app with a frontend/ (Vite) dir declares this bare plugin and
                     inherits node install + npm install + `npm run build` (at prepare-package). -->
                <plugin>
                    <groupId>com.github.eirslett</groupId>
                    <artifactId>frontend-maven-plugin</artifactId>
                    <version>${frontend-maven-plugin.version}</version>
                    <configuration>
                        <workingDirectory>frontend</workingDirectory>
                        <installDirectory>target</installDirectory>
                        <skip>${skipFrontend}</skip>
                    </configuration>
                    <executions>
                        <execution>
                            <id>install-node-and-npm</id>
                            <goals><goal>install-node-and-npm</goal></goals>
                            <configuration><nodeVersion>${node.version}</nodeVersion></configuration>
                        </execution>
                        <execution>
                            <id>npm-install</id>
                            <goals><goal>npm</goal></goals>
                            <configuration><arguments>install --no-audit --no-fund</arguments></configuration>
                        </execution>
                        <execution>
                            <id>npm-build</id>
                            <phase>prepare-package</phase>
                            <goals><goal>npm</goal></goals>
                            <configuration><arguments>run build</arguments></configuration>
                        </execution>
                    </executions>
                </plugin>
                <!-- Copy the built SPA (frontend/dist) into the jar's static/ so Spring serves it. -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>copy-frontend</id>
                            <phase>prepare-package</phase>
                            <goals><goal>copy-resources</goal></goals>
                            <configuration>
                                <skip>${skipFrontend}</skip>
                                <outputDirectory>${project.build.outputDirectory}/static</outputDirectory>
                                <resources>
                                    <resource><directory>frontend/dist</directory></resource>
                                </resources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

</project>
