<?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>ai.specformula</groupId>
        <artifactId>specformula</artifactId>
        <version>0.0.2</version>
    </parent>

    <artifactId>specformula-core</artifactId>
    <packaging>jar</packaging>

    <name>SpecFormula Core</name>
    <description>Core framework for SpecFormula - spec readers, instructions, and helpers</description>

    <dependencies>

        <!-- ==================== -->
        <!-- Main (compile scope) -->
        <!-- 會打包進 JAR，隨模組一起發佈 -->
        <!-- ==================== -->

        <!-- Cucumber DataTable / DocString - Instruction 類別使用的資料型別 -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>datatable</artifactId>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>docstring</artifactId>
        </dependency>

        <!-- Jackson YAML - 解析 isa.yml、entity_to_table_mapping.yml、OpenAPI YAML -->
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-yaml</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>

        <!-- ==================== -->
        <!-- Test (通用)          -->
        <!-- 僅供本模組測試使用，所有 profile 共用 -->
        <!-- ==================== -->

        <!-- Spring Test - 測試用 MockMvc（ApiCallTestContext Adapter 使用） -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>6.1.3</version>
            <scope>test</scope>
        </dependency>

        <!-- Spring Web - 測試用 HttpMethod 等型別（ApiCallTestContext Adapter 使用） -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>6.1.3</version>
            <scope>test</scope>
        </dependency>

        <!-- Servlet API - spring-test 所需 -->
        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <version>6.0.0</version>
            <scope>test</scope>
        </dependency>

        <!-- Cucumber 執行引擎 -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit-platform-engine</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- JUnit 5 -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-suite</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- Spring WebMVC - 測試用 MockMvcBuilders.standaloneSetup -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>6.1.3</version>
            <scope>test</scope>
        </dependency>

        <!-- H2 - 輕量 in-memory 資料庫，所有 profile 的測試程式碼共用 -->
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>2.2.224</version>
            <scope>test</scope>
        </dependency>

        <!-- Testcontainers Core API - 基礎型別 (JdbcDatabaseContainer)，測試程式碼編譯所需 -->
        <!-- 特定 DB container + JDBC driver 由各 profile 獨立引入 -->
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>testcontainers</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>jdbc</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <systemPropertyVariables>
                        <db.type>${db.type}</db.type>
                        <cucumber.filter.tags>${cucumber.filter.tags}</cucumber.filter.tags>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <!-- ============================================== -->
    <!-- Test (Profile 隔離)                           -->
    <!-- 各 DB 專屬的 Testcontainers module + JDBC driver -->
    <!-- 僅在指定 -P <profile> 時才引入，避免不必要的依賴  -->
    <!-- ============================================== -->
    <profiles>
        <!-- H2 (預設) - 不需要額外依賴，使用通用區的 H2 -->
        <profile>
            <id>h2</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <db.type>h2</db.type>
                <cucumber.filter.tags>not (@postgresql or @mysql or @mssql) or @h2</cucumber.filter.tags>
            </properties>
        </profile>

        <!-- PostgreSQL - Testcontainers PostgreSQL + JDBC Driver -->
        <profile>
            <id>postgresql</id>
            <properties>
                <db.type>postgresql</db.type>
                <cucumber.filter.tags>@postgresql</cucumber.filter.tags>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.testcontainers</groupId>
                    <artifactId>postgresql</artifactId>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.postgresql</groupId>
                    <artifactId>postgresql</artifactId>
                    <version>42.7.1</version>
                    <scope>test</scope>
                </dependency>
            </dependencies>
        </profile>

        <!-- MySQL - Testcontainers MySQL + JDBC Driver -->
        <profile>
            <id>mysql</id>
            <properties>
                <db.type>mysql</db.type>
                <cucumber.filter.tags>@mysql</cucumber.filter.tags>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.testcontainers</groupId>
                    <artifactId>mysql</artifactId>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>com.mysql</groupId>
                    <artifactId>mysql-connector-j</artifactId>
                    <version>8.2.0</version>
                    <scope>test</scope>
                </dependency>
            </dependencies>
        </profile>

        <!-- MSSQL - Testcontainers MSSQL Server + JDBC Driver -->
        <profile>
            <id>mssql</id>
            <properties>
                <db.type>mssql</db.type>
                <cucumber.filter.tags>@mssql</cucumber.filter.tags>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.testcontainers</groupId>
                    <artifactId>mssqlserver</artifactId>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>com.microsoft.sqlserver</groupId>
                    <artifactId>mssql-jdbc</artifactId>
                    <version>12.4.2.jre11</version>
                    <scope>test</scope>
                </dependency>
            </dependencies>
        </profile>
    </profiles>
</project>
