<?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">
    <parent>
        <artifactId>kafka-ui</artifactId>
        <groupId>com.provectus</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>kafka-ui-contract</artifactId>

    <profiles>
        <profile>
            <id>generate-spring-webflux-api</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>

            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-webflux</artifactId>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-validation</artifactId>
                </dependency>
                <dependency>
                    <groupId>io.swagger</groupId>
                    <artifactId>swagger-annotations</artifactId>
                    <version>${swagger-annotations.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.openapitools</groupId>
                    <artifactId>jackson-databind-nullable</artifactId>
                    <version>${jackson-databind-nullable.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.google.code.findbugs</groupId>
                    <artifactId>jsr305</artifactId>
                    <version>3.0.2</version>
                    <scope>provided</scope>
                </dependency>
            </dependencies>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.openapitools</groupId>
                        <artifactId>openapi-generator-maven-plugin</artifactId>
                        <version>${openapi-generator-maven-plugin.version}</version>
                        <executions>
                            <execution>
                                <id>generate-kafka-ui-client</id>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                                <configuration>
                                    <inputSpec>${project.basedir}/src/main/resources/swagger/kafka-ui-api.yaml
                                    </inputSpec>
                                    <output>${project.build.directory}/generated-sources/kafka-ui-client</output>
                                    <generatorName>java</generatorName>
                                    <generateApiTests>false</generateApiTests>
                                    <generateModelTests>false</generateModelTests>
                                    <configOptions>
                                        <modelPackage>com.provectus.kafka.ui.api.model</modelPackage>
                                        <apiPackage>com.provectus.kafka.ui.api.api</apiPackage>
                                        <sourceFolder>kafka-ui-client</sourceFolder>
                                        <asyncNative>true</asyncNative>
                                        <library>webclient</library>
                                        <useBeanValidation>true</useBeanValidation>
                                        <dateLibrary>java8</dateLibrary>
                                    </configOptions>
                                </configuration>
                            </execution>
                            <execution>
                                <id>generate-backend-api</id>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                                <configuration>
                                    <inputSpec>${project.basedir}/src/main/resources/swagger/kafka-ui-api.yaml
                                    </inputSpec>
                                    <output>${project.build.directory}/generated-sources/api</output>
                                    <generatorName>spring</generatorName>
                                    <modelNameSuffix>DTO</modelNameSuffix>
                                    <configOptions>
                                        <modelPackage>com.provectus.kafka.ui.model</modelPackage>
                                        <apiPackage>com.provectus.kafka.ui.api</apiPackage>
                                        <sourceFolder>kafka-ui-contract</sourceFolder>

                                        <reactive>true</reactive>

                                        <interfaceOnly>true</interfaceOnly>
                                        <skipDefaultInterface>true</skipDefaultInterface>
                                        <useBeanValidation>true</useBeanValidation>
                                        <useTags>true</useTags>

                                        <dateLibrary>java8</dateLibrary>
                                    </configOptions>
                                </configuration>
                            </execution>
                            <execution>
                                <id>generate-connect-client</id>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                                <configuration>
                                    <inputSpec>${project.basedir}/src/main/resources/swagger/kafka-connect-api.yaml
                                    </inputSpec>
                                    <output>${project.build.directory}/generated-sources/kafka-connect-client</output>
                                    <generatorName>java</generatorName>
                                    <generateApiTests>false</generateApiTests>
                                    <generateModelTests>false</generateModelTests>

                                    <configOptions>
                                        <modelPackage>com.provectus.kafka.ui.connect.model</modelPackage>
                                        <apiPackage>com.provectus.kafka.ui.connect.api</apiPackage>
                                        <sourceFolder>kafka-connect-client</sourceFolder>

                                        <asyncNative>true</asyncNative>
                                        <library>webclient</library>

                                        <useBeanValidation>true</useBeanValidation>
                                        <dateLibrary>java8</dateLibrary>
                                    </configOptions>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>com.github.eirslett</groupId>
                        <artifactId>frontend-maven-plugin</artifactId>
                        <version>${frontend-maven-plugin.version}</version>
                        <configuration>
                            <workingDirectory>../kafka-ui-react-app</workingDirectory>
                            <environmentVariables>
                                <VITE_TAG>${project.version}</VITE_TAG>
                            </environmentVariables>
                        </configuration>
                        <executions>
                            <execution>
                                <id>install node and pnpm</id>
                                <goals>
                                    <goal>install-node-and-pnpm</goal>
                                </goals>
                                <configuration>
                                    <nodeVersion>${node.version}</nodeVersion>
                                    <pnpmVersion>${pnpm.version}</pnpmVersion>
                                </configuration>
                            </execution>
                            <execution>
                                <id>pnpm install</id>
                                <goals>
                                    <goal>pnpm</goal>
                                </goals>
                                <configuration>
                                    <arguments>install</arguments>
                                </configuration>
                            </execution>
                            <execution>
                                <id>pnpm gen:sources</id>
                                <goals>
                                    <goal>pnpm</goal>
                                </goals>
                                <configuration>
                                    <arguments>gen:sources</arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-clean-plugin</artifactId>
                        <configuration>
                            <filesets>
                                <fileset>
                                    <directory>${basedir}/${frontend-generated-sources-directory}</directory>
                                </fileset>
                            </filesets>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-resources-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-resource-one</id>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>

                                <configuration>
                                    <outputDirectory>${basedir}/${frontend-generated-sources-directory}</outputDirectory>
                                    <resources>
                                        <resource>
                                            <directory>${project.build.directory}/generated-sources/frontend/</directory>
                                            <includes>
                                                <include>**/*.ts</include>
                                            </includes>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                        </executions>

                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
