<?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="shenobis_vip_spin_grant" resource="default" engine="innodb" comment="VIP Spin Grants">
        <column xsi:type="int" name="grant_id" unsigned="true" nullable="false" identity="true" comment="Grant ID"/>
        <column xsi:type="int" name="customer_id" unsigned="true" nullable="false" comment="Customer ID"/>
        <column xsi:type="int" name="spins_granted" unsigned="true" nullable="false" default="2" comment="Spins Granted"/>
        <column xsi:type="int" name="spins_used" unsigned="true" nullable="false" default="0" comment="Spins Used"/>
        <column xsi:type="varchar" name="source_type" nullable="false" length="64" comment="Source Type"/>
        <column xsi:type="varchar" name="source_ref" nullable="false" length="255" comment="Source Reference"/>
        <column xsi:type="varchar" name="subscription_id" nullable="true" length="255" comment="Stripe Subscription ID"/>
        <column xsi:type="varchar" name="sku" nullable="false" length="64" comment="Product SKU"/>
        <column xsi:type="text" name="comment" nullable="true" comment="Admin Comment"/>
        <column xsi:type="int" name="admin_user_id" unsigned="true" nullable="true" comment="Admin User ID"/>
        <column xsi:type="varchar" name="admin_user_name" nullable="true" length="255" comment="Admin User Name"/>
        <column xsi:type="timestamp" name="created_at" nullable="false" default="CURRENT_TIMESTAMP" on_update="false" comment="Created At"/>
        <column xsi:type="timestamp" name="expires_at" nullable="false" on_update="false" comment="Expires At"/>
        <constraint xsi:type="primary" referenceId="PRIMARY"><column name="grant_id"/></constraint>
        <constraint xsi:type="unique" referenceId="SHENOBIS_VIP_SPIN_GRANT_SOURCE_TYPE_SOURCE_REF">
            <column name="source_type"/><column name="source_ref"/>
        </constraint>
        <index referenceId="SHENOBIS_VIP_SPIN_GRANT_CUSTOMER_ID" indexType="btree"><column name="customer_id"/></index>
        <index referenceId="SHENOBIS_VIP_SPIN_GRANT_EXPIRES_AT" indexType="btree"><column name="expires_at"/></index>
        <index referenceId="SHENOBIS_VIP_SPIN_GRANT_SUBSCRIPTION_ID" indexType="btree"><column name="subscription_id"/></index>
        <index referenceId="SHENOBIS_VIP_SPIN_GRANT_ADMIN_USER_ID" indexType="btree"><column name="admin_user_id"/></index>
    </table>

    <table name="shenobis_vip_spin_wheel" resource="default" engine="innodb" comment="VIP Spin Wheels">
        <column xsi:type="int" name="wheel_id" unsigned="true" nullable="false" identity="true" comment="Wheel ID"/>
        <column xsi:type="varchar" name="code" nullable="false" length="64" comment="Wheel Code"/>
        <column xsi:type="varchar" name="name" nullable="false" length="255" comment="Wheel Name"/>
        <column xsi:type="text" name="description" nullable="true" comment="Description"/>
        <column xsi:type="smallint" name="is_active" unsigned="true" nullable="false" default="1" comment="Is Active"/>
        <column xsi:type="int" name="sort_order" nullable="false" default="0" comment="Sort Order"/>
        <column xsi:type="timestamp" name="created_at" nullable="false" default="CURRENT_TIMESTAMP" on_update="false" comment="Created At"/>
        <column xsi:type="timestamp" name="updated_at" nullable="false" default="CURRENT_TIMESTAMP" on_update="true" comment="Updated At"/>
        <constraint xsi:type="primary" referenceId="PRIMARY"><column name="wheel_id"/></constraint>
        <constraint xsi:type="unique" referenceId="SHENOBIS_VIP_SPIN_WHEEL_CODE"><column name="code"/></constraint>
        <index referenceId="SHENOBIS_VIP_SPIN_WHEEL_IS_ACTIVE" indexType="btree"><column name="is_active"/></index>
        <index referenceId="SHENOBIS_VIP_SPIN_WHEEL_SORT_ORDER" indexType="btree"><column name="sort_order"/></index>
    </table>

    <table name="shenobis_vip_spin_wheel_product" resource="default" engine="innodb" comment="VIP Spin Wheel Products">
        <column xsi:type="int" name="link_id" unsigned="true" nullable="false" identity="true" comment="Link ID"/>
        <column xsi:type="int" name="wheel_id" unsigned="true" nullable="false" comment="Wheel ID"/>
        <column xsi:type="int" name="product_id" unsigned="true" nullable="false" comment="Product ID"/>
        <column xsi:type="varchar" name="sku" nullable="false" length="64" comment="Product SKU"/>
        <column xsi:type="int" name="sort_order" nullable="false" default="0" comment="Sort Order"/>
        <constraint xsi:type="primary" referenceId="PRIMARY"><column name="link_id"/></constraint>
        <constraint xsi:type="unique" referenceId="SHENOBIS_VIP_SPIN_WHEEL_PRODUCT_UNQ"><column name="wheel_id"/><column name="product_id"/></constraint>
        <constraint xsi:type="foreign" referenceId="SHENOBIS_VIP_SPIN_WHEEL_PRODUCT_WHEEL_ID" table="shenobis_vip_spin_wheel_product" column="wheel_id" referenceTable="shenobis_vip_spin_wheel" referenceColumn="wheel_id" onDelete="CASCADE"/>
        <index referenceId="SHENOBIS_VIP_SPIN_WHEEL_PRODUCT_WHEEL_ID_IDX" indexType="btree"><column name="wheel_id"/></index>
        <index referenceId="SHENOBIS_VIP_SPIN_WHEEL_PRODUCT_PRODUCT_ID" indexType="btree"><column name="product_id"/></index>
    </table>

    <table name="shenobis_vip_spin_wheel_customer" resource="default" engine="innodb" comment="VIP Spin Wheel Customer Totals">
        <column xsi:type="int" name="wheel_customer_id" unsigned="true" nullable="false" identity="true" comment="Wheel Customer ID"/>
        <column xsi:type="int" name="wheel_id" unsigned="true" nullable="false" comment="Wheel ID"/>
        <column xsi:type="int" name="customer_id" unsigned="true" nullable="false" comment="Customer ID"/>
        <column xsi:type="int" name="spins_added" unsigned="true" nullable="false" default="0" comment="Spins Added To Wheel"/>
        <column xsi:type="timestamp" name="created_at" nullable="false" default="CURRENT_TIMESTAMP" on_update="false" comment="Created At"/>
        <column xsi:type="timestamp" name="updated_at" nullable="false" default="CURRENT_TIMESTAMP" on_update="true" comment="Updated At"/>
        <constraint xsi:type="primary" referenceId="PRIMARY"><column name="wheel_customer_id"/></constraint>
        <constraint xsi:type="unique" referenceId="SHENOBIS_VIP_SPIN_WHEEL_CUSTOMER_UNQ"><column name="wheel_id"/><column name="customer_id"/></constraint>
        <constraint xsi:type="foreign" referenceId="SHENOBIS_VIP_SPIN_WHEEL_CUSTOMER_WHEEL_ID" table="shenobis_vip_spin_wheel_customer" column="wheel_id" referenceTable="shenobis_vip_spin_wheel" referenceColumn="wheel_id" onDelete="CASCADE"/>
        <index referenceId="SHENOBIS_VIP_SPIN_WHEEL_CUSTOMER_WHEEL_ID_IDX" indexType="btree"><column name="wheel_id"/></index>
        <index referenceId="SHENOBIS_VIP_SPIN_WHEEL_CUSTOMER_CUSTOMER_ID" indexType="btree"><column name="customer_id"/></index>
    </table>

    <table name="shenobis_vip_spin_winner" resource="default" engine="innodb" comment="VIP Spin Winners">
        <column xsi:type="int" name="winner_id" unsigned="true" nullable="false" identity="true" comment="Winner ID"/>
        <column xsi:type="int" name="wheel_id" unsigned="true" nullable="false" comment="Wheel ID"/>
        <column xsi:type="int" name="customer_id" unsigned="true" nullable="false" comment="Customer ID"/>
        <column xsi:type="int" name="product_id" unsigned="true" nullable="false" comment="Product ID"/>
        <column xsi:type="varchar" name="sku" nullable="false" length="64" comment="Product SKU"/>
        <column xsi:type="int" name="spaces_removed" unsigned="true" nullable="false" default="0" comment="Winner Spaces Removed"/>
        <column xsi:type="int" name="order_id" unsigned="true" nullable="true" comment="Created Order ID"/>
        <column xsi:type="varchar" name="order_increment_id" nullable="true" length="32" comment="Created Order Increment ID"/>
        <column xsi:type="text" name="order_error" nullable="true" comment="Last Order Creation Error"/>
        <column xsi:type="timestamp" name="drawn_at" nullable="false" default="CURRENT_TIMESTAMP" on_update="false" comment="Drawn At"/>
        <constraint xsi:type="primary" referenceId="PRIMARY"><column name="winner_id"/></constraint>
        <constraint xsi:type="foreign" referenceId="SHENOBIS_VIP_SPIN_WINNER_WHEEL_ID" table="shenobis_vip_spin_winner" column="wheel_id" referenceTable="shenobis_vip_spin_wheel" referenceColumn="wheel_id" onDelete="CASCADE"/>
        <index referenceId="SHENOBIS_VIP_SPIN_WINNER_WHEEL_ID_IDX" indexType="btree"><column name="wheel_id"/></index>
        <index referenceId="SHENOBIS_VIP_SPIN_WINNER_CUSTOMER_ID" indexType="btree"><column name="customer_id"/></index>
        <index referenceId="SHENOBIS_VIP_SPIN_WINNER_PRODUCT_ID" indexType="btree"><column name="product_id"/></index>
        <index referenceId="SHENOBIS_VIP_SPIN_WINNER_ORDER_ID" indexType="btree"><column name="order_id"/></index>
        <index referenceId="SHENOBIS_VIP_SPIN_WINNER_DRAWN_AT" indexType="btree"><column name="drawn_at"/></index>
    </table>
</schema>
