<?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">
    <!-- 
        NOTE: The simplyin_order_id column on sales_order has been removed per audit recommendation.
        All SimplyIN order ID data is stored exclusively in the simplyin_order_sync table.
        The column still exists in db_schema_whitelist.json to allow Magento to handle the removal gracefully.
    -->

    <table name="simplyin_order_sync" resource="default" engine="innodb" comment="SimplyIN Order Sync Table">
        <column xsi:type="int" name="entity_id" padding="10" unsigned="true" nullable="false" identity="true" comment="Entity ID"/>
        <column xsi:type="int" name="order_id" padding="10" unsigned="true" nullable="false" comment="Magento Order ID"/>
        <column xsi:type="varchar" name="simplyin_order_id" nullable="true" length="255" comment="SimplyIN Order ID"/>
        <column xsi:type="varchar" name="sync_status" nullable="true" length="50" comment="Sync Status"/>
        <column xsi:type="timestamp" name="last_sync_at" on_update="false" nullable="true" comment="Last Sync Date"/>
        <column xsi:type="timestamp" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Created At"/>
        <column xsi:type="timestamp" name="updated_at" on_update="true" nullable="false" default="CURRENT_TIMESTAMP" comment="Updated At"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="entity_id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="SIMPLYIN_ORDER_SYNC_ORDER_ID_SALES_ORDER_ENTITY_ID" table="simplyin_order_sync" column="order_id" referenceTable="sales_order" referenceColumn="entity_id" onDelete="CASCADE"/>
        <constraint xsi:type="unique" referenceId="UNQ_SIMPLYIN_ORDER_SYNC_ORDER_ID">
            <column name="order_id"/>
        </constraint>
        <index referenceId="SIMPLYIN_ORDER_SYNC_SIMPLYIN_ORDER_ID" indexType="btree">
            <column name="simplyin_order_id"/>
        </index>
    </table>
</schema>
