<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.openfilz</groupId>
        <artifactId>openfilz-sdk</artifactId>
        <version>1.2.6</version>
    </parent>

    <artifactId>openfilz-sdk-java</artifactId>
    <packaging>jar</packaging>
    <name>OpenFilz Java SDK</name>
    <description>Java SDK for OpenFilz REST API</description>

    <dependencies>
        <!-- Reactor dependency for spec artifact ordering -->
        <dependency>
            <groupId>org.openfilz</groupId>
            <artifactId>openfilz-api</artifactId>
            <version>${project.version}</version>
            <type>json</type>
            <classifier>openapi</classifier>
            <scope>provided</scope>
        </dependency>

        <!-- Generated client runtime dependencies -->
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>4.12.0</version>
        </dependency>
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>logging-interceptor</artifactId>
            <version>4.12.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.11.0</version>
        </dependency>
        <dependency>
            <groupId>io.gsonfire</groupId>
            <artifactId>gson-fire</artifactId>
            <version>1.9.0</version>
        </dependency>
        <dependency>
            <groupId>io.swagger.core.v3</groupId>
            <artifactId>swagger-annotations</artifactId>
            <version>2.2.22</version>
        </dependency>
        <dependency>
            <groupId>javax.annotation</groupId>
            <artifactId>javax.annotation-api</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.findbugs</groupId>
            <artifactId>jsr305</artifactId>
            <version>3.0.2</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>

            <!-- Copy OpenAPI spec from openfilz-api artifact -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-openapi-spec</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.openfilz</groupId>
                                    <artifactId>openfilz-api</artifactId>
                                    <version>${project.version}</version>
                                    <type>json</type>
                                    <classifier>openapi</classifier>
                                    <outputDirectory>${project.build.directory}/openapi</outputDirectory>
                                    <destFileName>openfilz-api.json</destFileName>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Copy GraphQL schemas -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-graphql-schemas</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/classes/graphql</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${project.basedir}/../../openfilz-api/src/main/resources/graphql</directory>
                                    <includes>
                                        <include>**/*.graphqls</include>
                                    </includes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Generate Java SDK from OpenAPI spec -->
            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>${openapi-generator.version}</version>
                <executions>
                    <execution>
                        <id>generate-java-sdk</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${openapi.spec.uri}</inputSpec>
                            <generatorName>java</generatorName>
                            <output>${project.build.directory}/generated-sources/openapi</output>
                            <apiPackage>org.openfilz.sdk.api</apiPackage>
                            <modelPackage>org.openfilz.sdk.model</modelPackage>
                            <invokerPackage>org.openfilz.sdk</invokerPackage>
                            <groupId>org.openfilz</groupId>
                            <artifactId>openfilz-sdk-java</artifactId>
                            <artifactVersion>${project.version}</artifactVersion>
                            <gitUserId>openfilz</gitUserId>
                            <gitRepoId>openfilz-core</gitRepoId>
                            <inlineSchemaNameMappings>
                                <inlineSchemaNameMapping>AuditLog_details=AuditLogDetailsOneOf</inlineSchemaNameMapping>
                            </inlineSchemaNameMappings>
                            <configOptions>
                                <library>okhttp-gson</library>
                                <dateLibrary>java8</dateLibrary>
                                <useJakartaEe>true</useJakartaEe>
                                <sourceFolder>src/main/java</sourceFolder>
                                <legacyDiscriminatorBehavior>false</legacyDiscriminatorBehavior>
                                <licenseName>AGPL-3.0</licenseName>
                                <licenseUrl>https://www.gnu.org/licenses/agpl-3.0.html</licenseUrl>
                            </configOptions>
                            <generateApiTests>false</generateApiTests>
                            <generateModelTests>false</generateModelTests>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Add generated sources to compilation -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.6.0</version>
                <executions>
                    <execution>
                        <id>add-generated-sources</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>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>publishMaven</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <configuration>
                            <sourcepath>${project.build.directory}/generated-sources/openapi/src/main/java</sourcepath>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>
