<?xml version="1.0"?>
<!--
/**
 * Magezon
 *
 * This source file is subject to the Magezon Software License, which is available at https://www.magezon.com/license
 * Do not edit or add to this file if you wish to upgrade the to newer versions in the future.
 * If you wish to customize this module for your needs.
 * Please refer to https://www.magezon.com for more information.
 *
 * @category  Magezon
 * @package   Magezon_PopupBuilder
 * @copyright Copyright (C) 2020 Magezon (https://www.magezon.com)
 */
-->
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <table name="mgz_popupbuilder_popup" resource="default" engine="innodb" comment="Mgz PopupBuilder Popup Table">
        <column xsi:type="int" name="popup_id" unsigned="false" nullable="false" identity="true"
                comment="Popup ID"/>
        <column xsi:type="varchar" name="name" nullable="false" length="255" comment="Popup Name"/>
        <column xsi:type="longtext" name="content" nullable="true" comment="Content"/>
        <column xsi:type="longtext" name="conditions" nullable="true" comment="Conditions"/>
        <column xsi:type="longtext" name="display_settings" nullable="true" comment="Display Settings"/>
        <column xsi:type="longtext" name="style_settings" nullable="true" comment="Style Settings"/>
        <column xsi:type="date" name="from_date" comment="From Date"/>
        <column xsi:type="date" name="to_date" comment="To Date"/>
        <column xsi:type="smallint" name="is_active" unsigned="false" nullable="false" identity="false"
                default="1" comment="Is Popup Active"/>
        <column xsi:type="timestamp" name="creation_time" on_update="false" nullable="false" default="CURRENT_TIMESTAMP"
                comment="Popup Creation Time"/>
        <column xsi:type="timestamp" name="update_time" on_update="true" nullable="false" default="CURRENT_TIMESTAMP"
                comment="Popup Modification Time"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="popup_id"/>
        </constraint>
        <index referenceId="MGZ_POPUPBUILDER_POPUP_NAME_CONTENT" indexType="fulltext">
            <column name="name"/>
            <column name="content"/>
        </index>
    </table>
    <table name="mgz_popupbuilder_popup_store" resource="default" engine="innodb" comment="Mgz PopupBuilder Popup Store Table">
        <column xsi:type="int" name="popup_id" unsigned="false" nullable="false" identity="false"
                comment="Popup ID"/>
        <column xsi:type="smallint" name="store_id" unsigned="true" nullable="false" identity="false"
                comment="Store ID"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="popup_id"/>
            <column name="store_id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="MGZ_POPUPBUILDER_POPUP_STORE_POPUP_ID_MGZ_POPUPBUILDER_POPUP_POPUP_ID" table="mgz_popupbuilder_popup_store"
                    column="popup_id" referenceTable="mgz_popupbuilder_popup" referenceColumn="popup_id" onDelete="CASCADE"/>
        <constraint xsi:type="foreign" referenceId="MGZ_POPUPBUILDER_POPUP_STORE_STORE_ID_STORE_STORE_ID" table="mgz_popupbuilder_popup_store"
                    column="store_id" referenceTable="store" referenceColumn="store_id" onDelete="CASCADE"/>
        <index referenceId="MGZ_POPUPBUILDER_POPUP_STORE_STORE_ID" indexType="btree">
            <column name="store_id"/>
        </index>
    </table>
    <table name="mgz_popupbuilder_popup_customer_group" resource="default" engine="innodb" comment="Mgz PopupBuilder Popup To Customer Groups Relations">
        <column xsi:type="int" name="popup_id" unsigned="false" nullable="false" identity="false"
                comment="Popup ID"/>
        <column xsi:type="int" name="customer_group_id" padding="10" unsigned="true" nullable="false" identity="false"
                comment="Customer Group ID"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="popup_id"/>
            <column name="customer_group_id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="MGZ_POPUPBUILDER_POPUP_CUSTOMER_GROUP_POPUP_ID_MGZ_POPUPBUILDER_POPUP_POPUP_ID"
                    table="mgz_popupbuilder_popup_customer_group" column="popup_id" referenceTable="mgz_popupbuilder_popup"
                    referenceColumn="popup_id" onDelete="CASCADE"/>
        <constraint xsi:type="foreign" referenceId="MGZ_POPUPBUILDER_POPUP_CSTR_GROUP_CSTR_GROUP_ID_CSTR_GROUP_CSTR_GROUP_ID"
                    table="mgz_popupbuilder_popup_customer_group" column="customer_group_id" referenceTable="customer_group"
                    referenceColumn="customer_group_id" onDelete="CASCADE"/>
        <index referenceId="MGZ_POPUPBUILDER_POPUP_CUSTOMER_GROUP_CUSTOMER_GROUP_ID" indexType="btree">
            <column name="customer_group_id"/>
        </index>
    </table>
    <table name="mgz_popupbuilder_popup_report" resource="default" engine="innodb" comment="Mgz PopupBuilder Popup Report">
        <column xsi:type="int" name="index_id" unsigned="false" nullable="false" identity="true"
                comment="Index ID"/>
        <column xsi:type="int" name="customer_id" unsigned="false" nullable="true" identity="false"
                comment="Customer ID"/>
        <column xsi:type="int" name="popup_id" unsigned="false" nullable="false" identity="false"
                comment="Popup ID"/>
        <column xsi:type="varchar" name="type" nullable="false" length="255" comment="Type"/>
        <column xsi:type="smallint" name="store_id" unsigned="true" nullable="false" identity="false"
                comment="Store ID"/>
        <column xsi:type="timestamp" name="added_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Added Time"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="index_id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="MGZ_POPUPBUILDER_POPUP_REPORT_POPUP_ID_MGZ_POPUPBUILDER_POPUP_POPUP_ID" table="mgz_popupbuilder_popup_report"
                    column="popup_id" referenceTable="mgz_popupbuilder_popup" referenceColumn="popup_id" onDelete="CASCADE"/>
        <constraint xsi:type="foreign" referenceId="MGZ_POPUPBUILDER_POPUP_REPORT_STORE_ID_STORE_STORE_ID" table="mgz_popupbuilder_popup_report"
                    column="store_id" referenceTable="store" referenceColumn="store_id" onDelete="CASCADE"/>
        <index referenceId="MGZ_POPUPBUILDER_POPUP_REPORT_STORE_ID_ADDED_AT_POPUP_ID" indexType="btree">
            <column name="store_id"/>
            <column name="added_at"/>
            <column name="popup_id"/>
        </index>
    </table>
    <table name="mgz_popupbuilder_popup_salesrule" resource="default" engine="innodb" comment="Mgz PopupBuilder Popup To Rule Linkage Table">
        <column xsi:type="int" name="popup_id" unsigned="false" nullable="false" identity="false"
                comment="Popup ID"/>
        <column xsi:type="int" name="rule_id" padding="10" unsigned="true" nullable="false" identity="false"
                comment="Rule ID"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="popup_id"/>
            <column name="rule_id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="MGZ_POPUPBUILDER_POPUP_SALERULE_POPUP_ID_MGZ_POPUPBUILDER_POPUP_POPUP_ID" table="mgz_popupbuilder_popup_salesrule"
                    column="popup_id" referenceTable="mgz_popupbuilder_popup" referenceColumn="popup_id" onDelete="CASCADE"/>
        <constraint xsi:type="foreign" referenceId="MGZ_POPUPBUILDER_POPUP_SALERULE_RULE_ID_SALERULE_RULE_ID" table="mgz_popupbuilder_popup_salesrule"
                    column="rule_id" referenceTable="salesrule" referenceColumn="rule_id" onDelete="CASCADE"/>
        <index referenceId="MGZ_POPUPBUILDER_POPUP_SALERULE_RULE_ID" indexType="btree">
            <column name="rule_id"/>
        </index>
    </table>
    <table name="newsletter_subscriber">
        <column xsi:type="int" name="popup_id" nullable="true" comment="Popup ID"/>
    </table>
</schema>
