<?xml version="1.0" encoding="utf-8"?>
<!--
    This schema is to validate custom messages to Kafka topics migration XML files
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:simpleType name="QueryType">
        <xs:restriction base="xs:string" />
    </xs:simpleType>
    <xs:complexType name="MessageType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="key" type="xs:string" use="optional"></xs:attribute>
                <xs:attribute name="tombstone" type="xs:boolean" use="optional"></xs:attribute>
                <xs:attribute name="key_serializer" type="xs:string" use="optional"></xs:attribute>
                <xs:attribute name="value_serializer" type="xs:string" use="optional"></xs:attribute>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:complexType name="ChangesetType">
        <xs:sequence>
            <xs:element name="kafkamessage" type="MessageType" minOccurs="1" maxOccurs="1" />
        </xs:sequence>

        <xs:attribute name="id" type="xs:string" use="required" />
        <xs:attribute name="author" type="xs:string" use="required" />
        <xs:attribute name="topic" type="xs:string" use="required" />
        <xs:attribute name="run-always" type="xs:boolean" use="optional" />
        <xs:attribute name="run-on-change" type="xs:boolean" use="optional" />
        <xs:attribute name="kafka-cluster-name" type="xs:string" use="optional" />
    </xs:complexType>

    <xs:element name="changelog">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="changeset" type="ChangesetType" minOccurs="1" maxOccurs="unbounded" />
            </xs:sequence>
        </xs:complexType>
        <xs:unique name="unique_id">
            <xs:selector xpath="changeset" />
            <xs:field xpath="@id" />
        </xs:unique>
    </xs:element>
</xs:schema>
