<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>cashu-mint</artifactId>
        <version>0.18.1</version>
    </parent>

    <artifactId>cashu-mint-tools</artifactId>
    <packaging>jar</packaging>
    <version>0.18.1</version>

    <name>cashu-mint-tools</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!-- Default preload properties - can be overridden via -D or mint-preload.properties -->
        <mint.preload.json.output>scripts/preload-test-data.json</mint.preload.json.output>
        <mint.preload.mint-id>11111111-1111-1111-1111-111111111111</mint.preload.mint-id>
        <mint.preload.sql.input>scripts/preload-test-data.json</mint.preload.sql.input>
        <mint.preload.sql.output>scripts/preload-test-data.sql</mint.preload.sql.output>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>cashu-lib-common</artifactId>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>cashu-lib-entities</artifactId>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>cashu-lib-crypto</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <distributionManagement>
        <repository>
            <id>reposilite-releases</id>
            <url>https://maven.398ja.xyz/releases</url>
        </repository>
        <snapshotRepository>
            <id>reposilite-snapshots</id>
            <url>https://maven.398ja.xyz/snapshots</url>
        </snapshotRepository>
    </distributionManagement>

    <repositories>
        <repository>
            <id>reposilite-releases</id>
            <url>https://maven.398ja.xyz/releases</url>
        </repository>
        <repository>
            <id>reposilite-snapshots</id>
            <url>https://maven.398ja.xyz/snapshots</url>
        </repository>
    </repositories>

    <build>
        <plugins>
            <!-- Ensure classes are compiled before exec runs at validate -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <executions>
                    <execution>
                        <id>compile-early-for-exec</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>properties-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <phase>initialize</phase>
                        <goals>
                            <goal>read-project-properties</goal>
                        </goals>
                        <configuration>
                            <files>
                                <file>${project.basedir}/mint-preload.properties</file>
                            </files>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.5.0</version>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>preload-json</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <configuration>
                            <mainClass>xyz.tcheeric.cashu.mint.tools.MintPreloadDataGenerator</mainClass>
                            <workingDirectory>${project.parent.basedir}</workingDirectory>
                            <arguments>
                                <argument>${mint.preload.json.output}</argument>
                                <argument>${mint.preload.mint-id}</argument>
                            </arguments>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>preload-sql</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <configuration>
                            <mainClass>xyz.tcheeric.cashu.mint.tools.MintPreloadSqlRenderer</mainClass>
                            <workingDirectory>${project.parent.basedir}</workingDirectory>
                            <arguments>
                                <argument>${mint.preload.sql.input}</argument>
                                <argument>${mint.preload.sql.output}</argument>
                            </arguments>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- Run both generators in sequence: emits JSON then renders SQL. -->
        <profile>
            <id>preload-all</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>mint-preload-json</id>
                                <phase>validate</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                                <configuration>
                                    <mainClass>xyz.tcheeric.cashu.mint.tools.MintPreloadDataGenerator</mainClass>
                                    <workingDirectory>${project.parent.basedir}</workingDirectory>
                                    <arguments>
                                        <argument>${mint.preload.json.output}</argument>
                                        <argument>${mint.preload.mint-id}</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                            <execution>
                                <id>mint-preload-sql</id>
                                <phase>validate</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                                <configuration>
                                    <mainClass>xyz.tcheeric.cashu.mint.tools.MintPreloadSqlRenderer</mainClass>
                                    <workingDirectory>${project.parent.basedir}</workingDirectory>
                                    <arguments>
                                        <argument>${mint.preload.sql.input}</argument>
                                        <argument>${mint.preload.sql.output}</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
