<?xml version="1.0"?>
<!--
/**
 * ScandiPWA - Progressive Web App for Magento
 *
 * Copyright © Scandiweb, Inc. All rights reserved.
 * See LICENSE for license details.
 *
 * @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
 */
-->
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <table name="scandiweb_menumanager_menu" resource="default" engine="innodb">
        <column xsi:type="smallint" name="menu_id" padding="5" unsigned="true" nullable="false" identity="true"/>
        <column xsi:type="varchar" name="identifier" nullable="false" length="100"/>
        <column xsi:type="varchar" name="title" nullable="false" length="255"/>
        <column xsi:type="varchar" name="css_class" nullable="true" length="100"/>
        <column xsi:type="smallint" name="is_active" padding="6" unsigned="false" nullable="false" identity="false" default="1"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="menu_id"/>
        </constraint>
        <index referenceId="SCANDIWEB_MENUMANAGER_MENU_IDENTIFIER" indexType="btree">
            <column name="identifier"/>
        </index>
        <index referenceId="SCANDIWEB_MENUMANAGER_MENU_MENU_ID" indexType="btree">
            <column name="menu_id"/>
        </index>
    </table>

    <table name="scandiweb_menumanager_item" resource="default" engine="innodb">
        <column xsi:type="int" name="item_id" padding="10" unsigned="true" nullable="false" identity="true"/>
        <column xsi:type="smallint" name="menu_id" padding="5" unsigned="true" nullable="false" identity="false" default="0"/>
        <column xsi:type="smallint" name="parent_id" padding="6" unsigned="false" nullable="false" identity="false" default="0"/>
        <column xsi:type="varchar" name="title" nullable="false" length="255"/>
        <column xsi:type="varchar" name="item_class" nullable="false" length="255"/>
        <column xsi:type="varchar" name="identifier" nullable="false" length="100"/>
        <column xsi:type="text" name="url" nullable="true"/>
        <column xsi:type="smallint" name="open_type" padding="6" unsigned="false" nullable="false" identity="false" default="0"/>
        <column xsi:type="smallint" name="url_type" padding="6" unsigned="false" nullable="false" identity="false" default="0"/>
        <column xsi:type="smallint" name="cms_page_id" padding="6" unsigned="false" nullable="true" identity="false"/>
        <column xsi:type="int" name="category_id" padding="10" unsigned="true" nullable="true" identity="false"/>
        <column xsi:type="smallint" name="position" padding="6" unsigned="false" nullable="false" identity="false" default="0"/>
        <column xsi:type="smallint" name="is_active" padding="6" unsigned="false" nullable="false" identity="false" default="1"/>
        <column xsi:type="varchar" name="url_attributes" nullable="true" length="255"/>
        <column xsi:type="varchar" name="icon" nullable="true" length="255"/>
        <column xsi:type="varchar" name="icon_alt" nullable="true" length="255"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="item_id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="SCANDIWEB_MENUMANAGER_ITEM_MENU_ID" table="scandiweb_menumanager_item" column="menu_id" referenceTable="scandiweb_menumanager_menu" referenceColumn="menu_id" onDelete="CASCADE"/>
        <constraint xsi:type="foreign" referenceId="SCANDIWEB_MENUMANAGER_ITEM_CATEGORY_ID" table="scandiweb_menumanager_item" column="category_id" referenceTable="catalog_category_entity" referenceColumn="entity_id" onDelete="SET NULL"/>
        <constraint xsi:type="foreign" referenceId="SCANDIWEB_MENUMANAGER_ITEM_CMS_PAGE_ID" table="scandiweb_menumanager_item" column="cms_page_id" referenceTable="cms_page" referenceColumn="page_id" onDelete="SET NULL"/>
        <index referenceId="SCANDIWEB_MENUMANAGER_ITEM_IDENTIFIER" indexType="btree">
            <column name="identifier"/>
        </index>
    </table>

    <table name="scandiweb_menumanager_menu_store" resource="default" engine="innodb">
        <column xsi:type="smallint" name="menu_id" padding="5" unsigned="true" nullable="false" identity="false"/>
        <column xsi:type="smallint" name="store_id" padding="5" unsigned="true" nullable="false" identity="false"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="menu_id"/>
            <column name="store_id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="SCANDIWEB_MENUMANAGER_ITEM_MENU_ID" table="scandiweb_menumanager_menu_store" column="menu_id" referenceTable="scandiweb_menumanager_menu" referenceColumn="menu_id" onDelete="CASCADE"/>
        <constraint xsi:type="foreign" referenceId="SCANDIWEB_MENUMANAGER_ITEM_STORE_ID" table="scandiweb_menumanager_menu_store" column="store_id" referenceTable="store" referenceColumn="store_id" onDelete="CASCADE"/>
        <index referenceId="SCANDIWEB_MENUMANAGER_MENU_STORE_STORE_ID" indexType="btree">
            <column name="store_id"/>
        </index>
        <index referenceId="SCANDIWEB_MENUMANAGER_MENU_STORE_MENU_ID" indexType="btree">
            <column name="menu_id"/>
        </index>
    </table>
</schema>
