<?xml version="1.0"?>
<!--
/**
 * @author Amasty Team
 * @copyright Copyright (c) Amasty (https://www.amasty.com)
 * @package Pixel Core 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_pixel" resource="default" engine="innodb" comment="Amasty Pixel Entity">
        <column xsi:type="int" name="entity_id" unsigned="true" nullable="false" identity="true" comment="Entity Id"/>
        <column xsi:type="boolean" name="is_active" nullable="false" default="false" comment="Is Pixel Active"/>
        <column xsi:type="varchar" name="pixel_id" nullable="false" length="255" comment="Pixel Id"/>
        <column xsi:type="varchar" name="pixel_type" nullable="false" length="32" comment="Pixel Type"/>
        <column xsi:type="varchar" name="pixel_events" nullable="false" length="512"
                comment="Pixel Events (Serialized)"/>

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

        <index referenceId="AMASTY_PIXEL_IS_ACTIVE_PIXEL_TYPE" indexType="btree">
            <column name="is_active"/>
            <column name="pixel_type"/>
        </index>
    </table>

    <table name="amasty_pixel_store" resource="default" engine="innodb" comment="Amasty Pixel Store Relation">
        <column xsi:type="int" name="entity_id" unsigned="true" nullable="false" identity="true" comment="Entity Id"/>
        <column xsi:type="int" name="pixel_entity_id" unsigned="true" nullable="false" comment="Pixel Entity Id"/>
        <column xsi:type="smallint" name="store_id" unsigned="true" nullable="false" comment="Store ID"/>

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

        <constraint xsi:type="foreign" referenceId="AMASTY_PIXEL_STORE_PIXEL_ENTITY_ID_AMASTY_PIXEL_ENTITY_ID"
                    table="amasty_pixel_store" column="pixel_entity_id"
                    referenceTable="amasty_pixel" referenceColumn="entity_id" onDelete="CASCADE"/>
        <constraint xsi:type="foreign" referenceId="AMASTY_PIXEL_STORE_STORE_ID_STORE_STORE_ID"
                    table="amasty_pixel_store" column="store_id"
                    referenceTable="store" referenceColumn="store_id" onDelete="CASCADE"/>
    </table>
</schema>
