{%- import "cloudevents.jinja.include" as cloudEvents -%}
{%- import "kafka.jinja.include" as kafka -%}
{%- set uses_cloudevents = cloudEvents.usesCloudEvents(root) -%}
{%- set uses_kafka = kafka.uses_kafka_protocol(root) or kafka.uses_kafka_endpoint(root) -%}
{%- set uses_avro = (root | exists("dataschemaformat", "Avro")) -%}
{%- set uses_protobuf = (root | exists("dataschemaformat", "Protobuf")) -%}
{%- macro dep(name) -%}{{ dependency('java', 'jdk21', name) }}{%- endmacro -%}
<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>{{ project_name | lower | replace('-', '_') }}</groupId>
  <artifactId>kafka-producer</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  
  <name>{{ project_name }} Kafka Producer</name>
  <description>Kafka Producer generated from xRegistry</description>
  
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>21</maven.compiler.source>
    <maven.compiler.target>21</maven.compiler.target>
  </properties>
  
  {%- if uses_cloudevents or uses_avro %}
  <!-- Jackson BOM to enforce consistent versions across all transitive dependencies -->
  <dependencyManagement>
    <dependencies>
      {{ dep('jackson-bom') }}
    </dependencies>
  </dependencyManagement>
  {%- endif %}
  
  <dependencies>
    <!-- Apache Kafka Client -->
    {{ dep('kafka-clients') }}
    
    <!-- Logging -->
    {{ dep('log4j-api') }}
    {{ dep('log4j-core') }}
    {{ dep('log4j-slf4j2-impl') }}
    
    {%- if uses_cloudevents %}
    <!-- CloudEvents -->
    {{ dep('cloudevents-core') }}
    {{ dep('cloudevents-api') }}
    {{ dep('cloudevents-json-jackson') }}
    {{ dep('jackson-databind') }}
    {{ dep('jackson-core') }}
    {%- endif %}
    
    {%- if uses_avro %}
    <!-- Avro -->
    {{ dep('avro') }}
    {%- endif %}
    
    {%- if uses_protobuf %}
    <!-- Protocol Buffers -->
    {{ dep('protobuf-java') }}
    {%- endif %}
    
    <!-- Data project dependency -->
    {%- set package_parts = (data_project_name | lower).split('.') %}
    {%- if package_parts | length > 1 %}
    {%- set data_groupid = package_parts[:-1] | join('.') %}
    {%- set data_artifactid = package_parts[-1] %}
    {%- else %}
    {%- set data_groupid = package_parts[0] %}
    {%- set data_artifactid = package_parts[0] %}
    {%- endif %}
    <dependency>
      <groupId>{{ data_groupid }}</groupId>
      <artifactId>{{ data_artifactid }}</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
    
    <!-- Test dependencies -->
    {{ dep('org.junit.jupiter:junit-jupiter') }}
    {{ dep('org.testcontainers:testcontainers') }}
    {{ dep('org.testcontainers:junit-jupiter') }}
    {{ dep('org.testcontainers:kafka') }}
  </dependencies>
  
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.13.0</version>
        <configuration>
          <release>21</release>
          <encoding>UTF-8</encoding>
        </configuration>
      </plugin>
      
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.5.2</version>
      </plugin>
    </plugins>
  </build>
</project>
