<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>cn.atkon</groupId>
    <artifactId>atkonbase-sdk-java</artifactId>
    <version>1.1.1</version>
    <packaging>jar</packaging>

    <name>atkonbase-sdk-java</name>
    <description>ATKONBASE OpenAPI Java SDK — V1 + Public sharing (codegen + thin facade)</description>

    <url>https://atkonbase.example</url>
    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
        </license>
    </licenses>
    <developers>
        <developer>
            <name>ATKONBASE Team</name>
            <organization>YHCM</organization>
            <organizationUrl>https://atkonbase.example</organizationUrl>
        </developer>
    </developers>
    <scm>
        <url>https://atkonbase.example</url>
        <connection>scm:git:https://atkonbase.example/atkonbase-sdk-java.git</connection>
        <developerConnection>scm:git:https://atkonbase.example/atkonbase-sdk-java.git</developerConnection>
    </scm>

    <properties>
        <!-- 交叉编译到 JDK 8 字节码（bytecode major 52）：构建宿主仍须 ≥JDK11（codegen 插件要求），
             仅产物降级以兼容仍在 JDK 8 的集成方。须用 release 而非 source/target，
             且 maven-compiler-plugin 不得再显式声明 source/target，否则与 release 冲突报错。 -->
        <maven.compiler.release>8</maven.compiler.release>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <okhttp.version>4.12.0</okhttp.version>
        <gson.version>2.10.1</gson.version>
        <gson-fire.version>1.9.0</gson-fire.version>
        <!-- javax 注解（非 jakarta）：jakarta.annotation-api 2.x 字节码为 JDK 11、JDK 8 消费方加载即
             UnsupportedClassVersionError；javax.annotation-api 1.3.2 字节码 JDK 8 兼容。
             该工件只提供 @Generated；生成代码另用的 @Nonnull/@Nullable 属 JSR-305，须补 jsr305。 -->
        <javax-annotation.version>1.3.2</javax-annotation.version>
        <jsr305.version>3.0.2</jsr305.version>
        <jackson.version>2.17.2</jackson.version>
        <openapi-threeten-bp.version>1.6.8</openapi-threeten-bp.version>
        <openapi-generator-maven-plugin.version>7.6.0</openapi-generator-maven-plugin.version>
        <junit-jupiter.version>5.10.2</junit-jupiter.version>
        <mockwebserver.version>4.12.0</mockwebserver.version>
    </properties>

    <dependencies>
        <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>
        <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>${gson-fire.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.annotation</groupId>
            <artifactId>javax.annotation-api</artifactId>
            <version>${javax-annotation.version}</version>
        </dependency>
        <!-- 提供生成代码用的 javax.annotation.Nonnull / Nullable（javax.annotation-api 不含） -->
        <dependency>
            <groupId>com.google.code.findbugs</groupId>
            <artifactId>jsr305</artifactId>
            <version>${jsr305.version}</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>${junit-jupiter.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>mockwebserver</artifactId>
            <version>${mockwebserver.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>${project.basedir}</directory>
                <includes>
                    <include>LICENSE</include>
                </includes>
                <targetPath>META-INF</targetPath>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.13.0</version>
                <configuration>
                    <release>${maven.compiler.release}</release>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>

            <!-- 主 jar 打包：关闭 maven-archiver 默认清单项（Built-By / Build-Jdk / Created-By），
                 避免外发工件 MANIFEST 泄露构建机用户名与构建 JDK 等环境信息。release profile 的
                 sources/javadoc 占位 jar 复用同一 plugin 级配置，同样不写入构建机信息。 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.4.1</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addDefaultEntries>false</addDefaultEntries>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.2.5</version>
            </plugin>

            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>${openapi-generator-maven-plugin.version}</version>
                <executions>
                    <execution>
                        <id>generate-v1</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.basedir}/spec/openapi-v1.json</inputSpec>
                            <generatorName>java</generatorName>
                            <library>okhttp-gson</library>
                            <output>${project.build.directory}/generated-sources/openapi</output>
                            <apiPackage>cn.atkon.sdk.generated.api</apiPackage>
                            <modelPackage>cn.atkon.sdk.generated.model</modelPackage>
                            <invokerPackage>cn.atkon.sdk.generated.invoker</invokerPackage>
                            <generateApiTests>false</generateApiTests>
                            <generateModelTests>false</generateModelTests>
                            <generateApiDocumentation>false</generateApiDocumentation>
                            <generateModelDocumentation>false</generateModelDocumentation>
                            <generateSupportingFiles>true</generateSupportingFiles>
                            <skipOverwrite>false</skipOverwrite>
                            <!-- V1 时间 wire 为无偏移本地时间（yyyy-MM-dd HH:mm:ss）：把 date-time 映射为
                                 LocalDateTime（诚实对应无偏移语义），由 facade 的 WireDateTimeAdapter 注入显式
                                 formatter 承载读写双向。默认 OffsetDateTime 会按 ISO 带偏移解析、遇无偏移串即抛。 -->
                            <typeMappings>
                                <typeMapping>OffsetDateTime=LocalDateTime</typeMapping>
                            </typeMappings>
                            <!-- typeMapping 改了字段类型却保留原 OffsetDateTime import；这里按原始类型名为键
                                 把该 import 重定向到 java.time.LocalDateTime，使声明与 import 一致。 -->
                            <importMappings>
                                <importMapping>OffsetDateTime=java.time.LocalDateTime</importMapping>
                            </importMappings>
                            <configOptions>
                                <dateLibrary>java8</dateLibrary>
                                <java8>true</java8>
                                <hideGenerationTimestamp>true</hideGenerationTimestamp>
                                <openApiNullable>false</openApiNullable>
                                <serializableModel>true</serializableModel>
                                <useJakartaEe>false</useJakartaEe>
                            </configOptions>
                        </configuration>
                    </execution>
                    <execution>
                        <id>generate-public</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.basedir}/spec/openapi-public.json</inputSpec>
                            <generatorName>java</generatorName>
                            <library>okhttp-gson</library>
                            <output>${project.build.directory}/generated-sources/openapi-public</output>
                            <apiPackage>cn.atkon.sdk.generatedpublic.api</apiPackage>
                            <modelPackage>cn.atkon.sdk.generatedpublic.model</modelPackage>
                            <invokerPackage>cn.atkon.sdk.generatedpublic.invoker</invokerPackage>
                            <generateApiTests>false</generateApiTests>
                            <generateModelTests>false</generateModelTests>
                            <generateApiDocumentation>false</generateApiDocumentation>
                            <generateModelDocumentation>false</generateModelDocumentation>
                            <generateSupportingFiles>true</generateSupportingFiles>
                            <skipOverwrite>false</skipOverwrite>
                            <!-- 与 generate-v1 同口径：date-time→LocalDateTime，避免 OffsetDateTime 解析无偏移串抛异常 -->
                            <typeMappings>
                                <typeMapping>OffsetDateTime=LocalDateTime</typeMapping>
                            </typeMappings>
                            <!-- typeMapping 改了字段类型却保留原 OffsetDateTime import；这里按原始类型名为键
                                 把该 import 重定向到 java.time.LocalDateTime，使声明与 import 一致。 -->
                            <importMappings>
                                <importMapping>OffsetDateTime=java.time.LocalDateTime</importMapping>
                            </importMappings>
                            <configOptions>
                                <dateLibrary>java8</dateLibrary>
                                <java8>true</java8>
                                <hideGenerationTimestamp>true</hideGenerationTimestamp>
                                <openApiNullable>false</openApiNullable>
                                <serializableModel>true</serializableModel>
                                <useJakartaEe>false</useJakartaEe>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <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>
                                <source>${project.build.directory}/generated-sources/openapi-public/src/main/java</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jar-plugin</artifactId>
                        <version>3.4.1</version>
                        <executions>
                            <execution>
                                <id>empty-sources-jar</id>
                                <phase>package</phase>
                                <goals><goal>jar</goal></goals>
                                <configuration>
                                    <classifier>sources</classifier>
                                    <classesDirectory>${project.basedir}/src/publish-placeholder</classesDirectory>
                                </configuration>
                            </execution>
                            <execution>
                                <id>empty-javadoc-jar</id>
                                <phase>package</phase>
                                <goals><goal>jar</goal></goals>
                                <configuration>
                                    <classifier>javadoc</classifier>
                                    <classesDirectory>${project.basedir}/src/publish-placeholder</classesDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>3.2.4</version>
                        <configuration>
                            <gpgArguments>
                                <arg>--pinentry-mode</arg>
                                <arg>loopback</arg>
                            </gpgArguments>
                        </configuration>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals><goal>sign</goal></goals>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.sonatype.central</groupId>
                        <artifactId>central-publishing-maven-plugin</artifactId>
                        <version>0.11.0</version>
                        <extensions>true</extensions>
                        <configuration>
                            <publishingServerId>central</publishingServerId>
                            <autoPublish>false</autoPublish>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
