<?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>

    <groupId>ai.cardsight</groupId>
    <artifactId>cardsightai-sdk-java</artifactId>
    <version>1.0.2</version>
    <packaging>jar</packaging>

    <name>CardSight AI Java SDK</name>
    <description>Java SDK for CardSight AI - Trading Card Identification and Collection Management API</description>
    <url>https://github.com/CardSightAI/cardsightai-sdk-java</url>

    <licenses>
        <license>
            <name>MIT License</name>
            <url>https://opensource.org/licenses/MIT</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <developers>
        <developer>
            <name>CardSight AI</name>
            <email>support@cardsight.ai</email>
            <organization>CardSight AI</organization>
            <organizationUrl>https://cardsight.ai</organizationUrl>
        </developer>
    </developers>

    <scm>
        <connection>scm:git:git://github.com/CardSightAI/cardsightai-sdk-java.git</connection>
        <developerConnection>scm:git:git@github.com:CardSightAI/cardsightai-sdk-java.git</developerConnection>
        <url>https://github.com/CardSightAI/cardsightai-sdk-java</url>
    </scm>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>21</maven.compiler.source>
        <maven.compiler.target>21</maven.compiler.target>
        <maven.compiler.release>21</maven.compiler.release>

        <!-- Dependency versions -->
        <okhttp.version>4.12.0</okhttp.version>
        <gson.version>2.11.0</gson.version>
        <slf4j.version>2.0.16</slf4j.version>
        <junit.version>5.11.3</junit.version>
        <mockito.version>5.14.2</mockito.version>
        <openapi-generator.version>7.17.0</openapi-generator.version>
        <jakarta.annotation.version>3.0.0</jakarta.annotation.version>
        <jakarta.validation.version>3.1.0</jakarta.validation.version>
        <jakarta.inject.version>2.0.1</jakarta.inject.version>
        <findbugs.version>3.0.2</findbugs.version>
        <org.jspecify.version>1.0.0</org.jspecify.version>
    </properties>

    <dependencies>
        <!-- HTTP Client -->
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>${okhttp.version}</version>
        </dependency>

        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>logging-interceptor</artifactId>
            <version>${okhttp.version}</version>
        </dependency>

        <!-- Apache HttpClient (for generated code) -->
        <dependency>
            <groupId>org.apache.httpcomponents.client5</groupId>
            <artifactId>httpclient5</artifactId>
            <version>5.3.1</version>
        </dependency>

        <!-- JSON Processing -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>${gson.version}</version>
        </dependency>

        <dependency>
            <groupId>io.gsonfire</groupId>
            <artifactId>gson-fire</artifactId>
            <version>1.9.0</version>
        </dependency>

        <!-- Jackson for JSON processing (used by native library) -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.18.1</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
            <version>2.18.1</version>
        </dependency>

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

        <!-- Jakarta Annotations (for generated code) -->
        <dependency>
            <groupId>jakarta.annotation</groupId>
            <artifactId>jakarta.annotation-api</artifactId>
            <version>${jakarta.annotation.version}</version>
        </dependency>

        <dependency>
            <groupId>jakarta.validation</groupId>
            <artifactId>jakarta.validation-api</artifactId>
            <version>${jakarta.validation.version}</version>
        </dependency>

        <!-- Jakarta Inject (for dependency injection support) -->
        <dependency>
            <groupId>jakarta.inject</groupId>
            <artifactId>jakarta.inject-api</artifactId>
            <version>${jakarta.inject.version}</version>
        </dependency>

        <!-- FindBugs annotations (for generated code) -->
        <dependency>
            <groupId>com.google.code.findbugs</groupId>
            <artifactId>jsr305</artifactId>
            <version>${findbugs.version}</version>
        </dependency>

        <dependency>
          <groupId>org.jspecify</groupId>
          <artifactId>jspecify</artifactId>
          <version>${org.jspecify.version}</version>
        </dependency>

        <!-- Test Dependencies -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>mockwebserver</artifactId>
            <version>${okhttp.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>${slf4j.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <sourceDirectory>src/main/java</sourceDirectory>
        <testSourceDirectory>src/test/java</testSourceDirectory>

        <plugins>
            <!-- Maven Compiler Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.13.0</version>
                <configuration>
                    <release>21</release>
                    <enablePreview>false</enablePreview>
                </configuration>
            </plugin>

            <!-- Preprocess OpenAPI Spec -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>preprocess-openapi</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>node</executable>
                            <arguments>
                                <argument>${project.basedir}/preprocess-openapi.js</argument>
                                <argument>${project.basedir}/src/main/resources/openapi.json</argument>
                                <argument>${project.basedir}/src/main/resources/openapi-fixed.json</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- OpenAPI Generator Plugin -->
            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>${openapi-generator.version}</version>
                <executions>
                    <execution>
                        <id>generate-api</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.basedir}/src/main/resources/openapi-fixed.json</inputSpec>
                            <generatorName>java</generatorName>
                            <library>okhttp-gson</library>
                            <output>${project.build.directory}/generated-sources/openapi</output>
                            <apiPackage>ai.cardsight.generated.api</apiPackage>
                            <modelPackage>ai.cardsight.generated.model</modelPackage>
                            <invokerPackage>ai.cardsight.generated.client</invokerPackage>
                            <generateApiTests>false</generateApiTests>
                            <generateModelTests>false</generateModelTests>
                            <generateApiDocumentation>false</generateApiDocumentation>
                            <generateModelDocumentation>false</generateModelDocumentation>
                            <configOptions>
                                <sourceFolder>src/main/java</sourceFolder>
                                <useJakartaEe>true</useJakartaEe>
                                <dateLibrary>java8</dateLibrary>
                                <openApiNullable>false</openApiNullable>
                                <hideGenerationTimestamp>true</hideGenerationTimestamp>
                                <disallowAdditionalPropertiesIfNotPresent>false</disallowAdditionalPropertiesIfNotPresent>
                                <modelPropertyNaming>camelCase</modelPropertyNaming>
                                <ensureUniqueParams>true</ensureUniqueParams>
                                <legacyDiscriminatorBehavior>true</legacyDiscriminatorBehavior>
                                <allowUnicodeIdentifiers>false</allowUnicodeIdentifiers>
                            </configOptions>
                            <!-- Map conflicting property names to avoid Java setter conflicts -->
                            <nameMappings>
                                setName=cardSetName,
                                setId=cardSetId
                            </nameMappings>
                            <!-- Map conflicting model names to avoid Java class conflicts -->
                            <modelNameMappings>
                                Set=CardSet
                            </modelNameMappings>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Build Helper Plugin to add generated sources -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.6.0</version>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.build.directory}/generated-sources/openapi/src/main/java</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Maven Surefire Plugin for running tests -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.5.2</version>
            </plugin>

            <!-- Maven Source Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.3.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!-- Maven Javadoc Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.11.1</version>
                <configuration>
                    <release>21</release>
                    <additionalOptions>
                        <additionalOption>-Xdoclint:none</additionalOption>
                    </additionalOptions>
                    <excludePackageNames>ai.cardsight.generated.*</excludePackageNames>
                </configuration>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!-- Central Publishing Maven Plugin -->
            <plugin>
                <groupId>org.sonatype.central</groupId>
                <artifactId>central-publishing-maven-plugin</artifactId>
                <version>0.6.0</version>
                <extensions>true</extensions>
                <configuration>
                    <publishingServerId>central</publishingServerId>
                    <autoPublish>false</autoPublish>
                    <waitUntil>validated</waitUntil>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <!-- Profile for downloading fresh OpenAPI spec -->
        <profile>
            <id>download-spec</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.googlecode.maven-download-plugin</groupId>
                        <artifactId>download-maven-plugin</artifactId>
                        <version>1.9.0</version>
                        <executions>
                            <execution>
                                <id>download-openapi-spec</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>wget</goal>
                                </goals>
                                <configuration>
                                    <url>https://api.cardsight.ai/documentation/json</url>
                                    <outputDirectory>${project.basedir}/src/main/resources</outputDirectory>
                                    <outputFileName>openapi.json</outputFileName>
                                    <overwrite>true</overwrite>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- Profile for releasing to Maven Central -->
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <!-- GPG Plugin for signing artifacts -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>3.2.8</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                                <configuration>
                                    <gpgArguments>
                                        <arg>--pinentry-mode</arg>
                                        <arg>loopback</arg>
                                    </gpgArguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
