<?xml version="1.0"?>
<!--
/**
 * @author Amasty Team
 * @copyright Copyright (c) 2023 Amasty (https://www.amasty.com)
 * @package Landing Pages for Magento 2
 */-->
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <table name="amasty_xlanding_page" resource="default" engine="innodb" comment="CMS Page Table">
        <column xsi:type="smallint" name="page_id" padding="6" unsigned="false" nullable="false" identity="true" comment="Page ID"/>
        <column xsi:type="varchar" name="title" nullable="true" length="255" comment="Title"/>
        <column xsi:type="varchar" name="meta_title" nullable="true" length="255" comment="Meta Title" disabled="true"/>
        <column xsi:type="text" name="meta_keywords" nullable="true" comment="Page Meta Keywords" disabled="true"/>
        <column xsi:type="text" name="meta_description" nullable="true" comment="Page Meta Description" disabled="true"/>
        <column xsi:type="varchar" name="identifier" nullable="true" length="100" comment="Page String Identifier"/>
        <column xsi:type="varchar" name="page_layout" nullable="true" length="255" comment="Page Layout"/>
        <column xsi:type="varchar" name="layout_columns_count" nullable="true" length="255" comment="Layout Columns Count"/>
        <column xsi:type="smallint"
                name="layout_include_navigation"
                padding="6"
                unsigned="false"
                nullable="false"
                identity="false" default="1"
                comment="Layout Include Navigation"/>
        <column xsi:type="varchar" name="layout_heading" nullable="true" length="255" comment="Layout Heading"/>
        <column xsi:type="varchar" name="layout_file" nullable="true" length="255" comment="Layout File"/>
        <column xsi:type="varchar" name="layout_file_alt" nullable="true" length="255" comment="Layout File Alt"/>
        <column xsi:type="mediumtext" name="layout_top_description" nullable="true" comment="Layout Top Description"/>
        <column xsi:type="mediumtext" name="layout_bottom_description" nullable="true" comment="Layout Bottom Description"/>
        <column xsi:type="varchar" name="layout_static_top" nullable="true" length="255" comment="Layout Static Top"/>
        <column xsi:type="varchar" name="layout_static_bottom" nullable="true" length="255" comment="Layout Static Bottom"/>
        <column xsi:type="varchar" name="default_sort_by" nullable="true" length="255" comment="Default Sort By"/>
        <column xsi:type="timestamp" name="creation_time" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Page Creation Time"/>
        <column xsi:type="timestamp" name="update_time" on_update="true" nullable="false" default="CURRENT_TIMESTAMP" comment="Page Modification Time"/>
        <column xsi:type="smallint" name="is_active" padding="6" unsigned="false" nullable="false" identity="false" default="1" comment="Is Page Active"/>
        <column xsi:type="smallint" name="sort_order" padding="6" unsigned="false" nullable="false" identity="false" default="0" comment="Page Sort Order"/>
        <column xsi:type="text" name="layout_update_xml" nullable="true" comment="Page Layout Update Content"/>
        <column xsi:type="mediumtext" name="conditions_serialized" nullable="true" comment="Conditions Serialized"/>
        <column xsi:type="text" name="meta_data" nullable="true" comment="Meta data" />
        <column xsi:type="smallint"
                name="dynamic_category_id"
                nullable="false"
                comment="Dynamic Category Id"
                padding="6"
                unsigned="true"
                identity="false"
                default="0"/>

        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="page_id"/>
        </constraint>

        <constraint xsi:type="unique" referenceId="AMASTY_XLANDING_PAGE_IDENTIFIER" disabled="true">
            <column name="identifier"/>
        </constraint>

        <index referenceId="FTI_0CB3967B231C66CB669A77A3DADBE0FA" indexType="fulltext">
            <column name="title"/>
            <column name="identifier"/>
        </index>

        <index referenceId="AMASTY_XLANDING_PAGE_LYT_BOTTOM_DESCRIPTION_LYT_TOP_DESCRIPTION" indexType="fulltext">
            <column name="layout_bottom_description"/>
            <column name="layout_top_description"/>
        </index>
    </table>

    <table name="amasty_xlanding_page_store" resource="default" engine="innodb" comment="CMS Page To Store Linkage Table">
        <column xsi:type="smallint" name="page_id" padding="6" unsigned="false" nullable="false" identity="false" comment="Page ID"/>
        <column xsi:type="smallint" name="store_id" padding="5" unsigned="true" nullable="false" identity="false" comment="Store ID"/>

        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="page_id"/>
            <column name="store_id"/>
        </constraint>

        <constraint xsi:type="foreign"
                    referenceId="AMASTY_XLANDING_PAGE_STORE_PAGE_ID_AMASTY_XLANDING_PAGE_PAGE_ID"
                    table="amasty_xlanding_page_store"
                    column="page_id"
                    referenceTable="amasty_xlanding_page"
                    referenceColumn="page_id"
                    onDelete="CASCADE"/>

        <constraint xsi:type="foreign"
                    referenceId="AMASTY_XLANDING_PAGE_STORE_STORE_ID_STORE_STORE_ID"
                    table="amasty_xlanding_page_store"
                    column="store_id"
                    referenceTable="store"
                    referenceColumn="store_id"
                    onDelete="CASCADE"/>

        <index referenceId="AMASTY_XLANDING_PAGE_STORE_STORE_ID" indexType="btree">
          <column name="store_id"/>
        </index>
    </table>

    <table name="amasty_xlanding_page_product" resource="default" engine="innodb" comment="Catalog Product To Laning Page Linkage Table">
        <column xsi:type="int" name="page_id" padding="10" unsigned="true" nullable="false" identity="false" default="0" comment="Page ID"/>
        <column xsi:type="int" name="product_id" padding="10" unsigned="true" nullable="false" identity="false" default="0" comment="Product ID"/>
        <column xsi:type="smallint" name="store_id" padding="5" unsigned="true" nullable="false" identity="false" default="0" comment="Store ID"/>
        <column xsi:type="int" name="position" padding="11" unsigned="false" nullable="false" identity="false" default="0" comment="Position"/>

        <constraint xsi:type="foreign"
                    referenceId="AMASTY_XLANDING_PAGE_PRD_PRD_ID_CAT_PRD_ENTT_ENTT_ID"
                    table="amasty_xlanding_page_product"
                    column="product_id"
                    referenceTable="catalog_product_entity"
                    referenceColumn="entity_id"
                    onDelete="CASCADE"/>

        <constraint xsi:type="unique" referenceId="AMASTY_XLANDING_PAGE_PRODUCT_PAGE_ID_PRODUCT_ID_STORE_ID">
            <column name="page_id"/>
            <column name="product_id"/>
            <column name="store_id"/>
        </constraint>

        <index referenceId="AMASTY_XLANDING_PAGE_PRODUCT_PRODUCT_ID" indexType="btree">
            <column name="product_id"/>
        </index>

        <index referenceId="AMASTY_XLANDING_PAGE_PRODUCT_PAGE_ID" indexType="btree">
            <column name="page_id"/>
        </index>
    </table>

    <table name="amasty_xlanding_page_product_index" resource="default" engine="innodb" comment="Catalog Product To Laning Page Linkage Index Table">
        <column xsi:type="int" name="page_id" padding="10" unsigned="true" nullable="false" identity="false" default="0" comment="Page ID"/>
        <column xsi:type="int" name="product_id" padding="10" unsigned="true" nullable="false" identity="false" default="0" comment="Product ID"/>
        <column xsi:type="smallint" name="store_id" padding="5" unsigned="true" nullable="false" identity="false" default="0" comment="Store ID"/>
        <column xsi:type="int" name="position" padding="11" unsigned="false" nullable="false" identity="false" default="0" comment="Position"/>

        <constraint xsi:type="foreign"
                    referenceId="AMASTY_XLANDING_PAGE_PRD_IDX_PRD_ID_CAT_PRD_ENTT_ENTT_ID"
                    table="amasty_xlanding_page_product_index"
                    column="product_id"
                    referenceTable="catalog_product_entity"
                    referenceColumn="entity_id"
                    onDelete="CASCADE"/>

        <constraint xsi:type="foreign"
                    referenceId="AMASTY_XLANDING_PAGE_PRD_IDX_PRD_ID_CAT_PRD_ENTT_ROW_ID"
                    table="amasty_xlanding_page_product_index"
                    column="product_id"
                    referenceTable="catalog_product_entity"
                    referenceColumn="row_id"
                    onDelete="CASCADE"
                    disabled="true"/>

        <constraint xsi:type="unique" referenceId="AMASTY_XLANDING_PAGE_PRODUCT_INDEX_PAGE_ID_PRODUCT_ID_STORE_ID">
            <column name="page_id"/>
            <column name="product_id"/>
            <column name="store_id"/>
        </constraint>

        <index referenceId="AMASTY_XLANDING_PAGE_PRODUCT_INDEX_PRODUCT_ID" indexType="btree">
            <column name="product_id"/>
        </index>

        <index referenceId="AMASTY_XLANDING_PAGE_PRODUCT_INDEX_PAGE_ID" indexType="btree">
            <column name="page_id"/>
        </index>
    </table>
</schema>
