<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <table name="sales_order" resource="default">
        <column xsi:type="varchar" name="tbi_status" length="255" nullable="true" comment="TBI Status"/>
    </table>
    <table name="autogedal_tbi_application" resource="default" engine="innodb" comment="TBI application polling metadata">
        <column xsi:type="int" name="order_id" unsigned="true" nullable="false" comment="Magento Order ID"/>
        <column xsi:type="int" name="provider_order_id" unsigned="true" nullable="false" comment="TBI Application ID"/>
        <column xsi:type="text" name="token" nullable="false" comment="Encrypted TBI Application Token"/>
        <column xsi:type="varchar" name="account_fingerprint" length="64" nullable="false" comment="TBI Account Fingerprint"/>
        <column xsi:type="varchar" name="last_status" length="255" nullable="true" comment="Last Verified TBI Status"/>
        <column xsi:type="timestamp" name="last_checked_at" nullable="true" on_update="false" comment="Last Poll Attempt UTC"/>
        <constraint xsi:type="primary" referenceId="PRIMARY"><column name="order_id"/></constraint>
        <constraint xsi:type="foreign" referenceId="AUTOGEDAL_TBI_APPLICATION_ORDER_ID_SALES_ORDER_ENTITY_ID" table="autogedal_tbi_application" column="order_id" referenceTable="sales_order" referenceColumn="entity_id" onDelete="CASCADE"/>
        <index referenceId="AUTOGEDAL_TBI_APPLICATION_POLL" indexType="btree"><column name="account_fingerprint"/><column name="last_checked_at"/></index>
    </table>
</schema>
