<?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="autogedal_stock_log" resource="default" engine="innodb" comment="Stock Change Audit Log">
        <column xsi:type="int" name="log_id" unsigned="true" nullable="false" identity="true" comment="Log ID"/>
        <column xsi:type="int" name="product_id" unsigned="true" nullable="true" comment="Product ID"/>
        <column xsi:type="varchar" name="sku" nullable="false" length="255" comment="SKU"/>
        <column xsi:type="decimal" name="qty_before" scale="4" precision="12" unsigned="false" nullable="false" default="0" comment="Qty Before"/>
        <column xsi:type="decimal" name="qty_after" scale="4" precision="12" unsigned="false" nullable="false" default="0" comment="Qty After"/>
        <column xsi:type="smallint" name="is_in_stock_before" unsigned="true" nullable="false" default="0" comment="Is In Stock Before"/>
        <column xsi:type="smallint" name="is_in_stock_after" unsigned="true" nullable="false" default="0" comment="Is In Stock After"/>
        <column xsi:type="varchar" name="source" nullable="false" length="100" default="unknown" comment="Change Source"/>
        <column xsi:type="int" name="admin_user_id" unsigned="true" nullable="true" comment="Admin User ID"/>
        <column xsi:type="varchar" name="admin_username" nullable="true" length="255" comment="Admin Username"/>
        <column xsi:type="datetime" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Created At"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="log_id"/>
        </constraint>
        <index referenceId="AUTOGEDAL_STOCK_LOG_SKU_CREATED_AT" indexType="btree">
            <column name="sku"/>
            <column name="created_at"/>
        </index>
        <index referenceId="AUTOGEDAL_STOCK_LOG_SOURCE_CREATED_AT" indexType="btree">
            <column name="source"/>
            <column name="created_at"/>
        </index>
        <index referenceId="AUTOGEDAL_STOCK_LOG_PRODUCT_ID_CREATED_AT" indexType="btree">
            <column name="product_id"/>
            <column name="created_at"/>
        </index>
    </table>

    <table name="autogedal_stock_log_archive" resource="default" engine="innodb" comment="Stock Change Audit Log — Archive">
        <column xsi:type="int" name="archive_id" unsigned="true" nullable="false" identity="true" comment="Archive ID"/>
        <column xsi:type="int" name="log_id" unsigned="true" nullable="false" comment="Original Log ID"/>
        <column xsi:type="int" name="product_id" unsigned="true" nullable="true" comment="Product ID"/>
        <column xsi:type="varchar" name="sku" nullable="false" length="255" comment="SKU"/>
        <column xsi:type="decimal" name="qty_before" scale="4" precision="12" unsigned="false" nullable="false" default="0" comment="Qty Before"/>
        <column xsi:type="decimal" name="qty_after" scale="4" precision="12" unsigned="false" nullable="false" default="0" comment="Qty After"/>
        <column xsi:type="smallint" name="is_in_stock_before" unsigned="true" nullable="false" default="0" comment="Is In Stock Before"/>
        <column xsi:type="smallint" name="is_in_stock_after" unsigned="true" nullable="false" default="0" comment="Is In Stock After"/>
        <column xsi:type="varchar" name="source" nullable="false" length="100" default="unknown" comment="Change Source"/>
        <column xsi:type="int" name="admin_user_id" unsigned="true" nullable="true" comment="Admin User ID"/>
        <column xsi:type="varchar" name="admin_username" nullable="true" length="255" comment="Admin Username"/>
        <column xsi:type="datetime" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Original Created At"/>
        <column xsi:type="datetime" name="archived_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Archived At"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="archive_id"/>
        </constraint>
        <constraint xsi:type="unique" referenceId="AUTOGEDAL_STOCK_LOG_ARCHIVE_LOG_ID">
            <column name="log_id"/>
        </constraint>
        <index referenceId="AUTOGEDAL_STOCK_LOG_ARCHIVE_SKU_CREATED_AT" indexType="btree">
            <column name="sku"/>
            <column name="created_at"/>
        </index>
        <index referenceId="AUTOGEDAL_STOCK_LOG_ARCHIVE_ARCHIVED_AT" indexType="btree">
            <column name="archived_at"/>
        </index>
    </table>
</schema>
