<?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="autogedal_blackfriday_sku" resource="default" engine="innodb" comment="Black Friday product list">
        <column xsi:type="varchar" name="sku" length="64" nullable="false" comment="SKU from the uploaded list"/>
        <column xsi:type="int" name="product_id" unsigned="true" nullable="true" comment="Resolved product id"/>
        <column xsi:type="decimal" name="sales_rank" scale="4" precision="12" unsigned="false" nullable="false" default="0" comment="Qty sold in the bestseller period"/>
        <column xsi:type="timestamp" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Imported at"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="sku"/>
        </constraint>
        <index referenceId="AUTOGEDAL_BLACKFRIDAY_SKU_PRODUCT_ID" indexType="btree">
            <column name="product_id"/>
        </index>
    </table>
    <table name="autogedal_blackfriday_subscriber" resource="default" engine="innodb" comment="Black Friday landing page subscribers and favourites">
        <column xsi:type="int" name="entity_id" unsigned="true" nullable="false" identity="true" comment="Id"/>
        <column xsi:type="smallint" name="store_id" unsigned="true" nullable="false" default="0" comment="Store"/>
        <column xsi:type="varchar" name="email" length="255" nullable="false" comment="Email"/>
        <column xsi:type="varchar" name="token" length="64" nullable="false" comment="Secret kept in the browser to update the favourites"/>
        <column xsi:type="text" name="device_tokens" nullable="true" comment="SHA-256 of the tokens given to later subscriptions of the email (JSON)"/>
        <column xsi:type="text" name="favorites" nullable="true" comment="Favourite SKUs, comma separated"/>
        <column xsi:type="int" name="favorites_count" unsigned="true" nullable="false" default="0" comment="Number of favourites"/>
        <column xsi:type="varchar" name="utm_source" length="255" nullable="true" comment="utm_source"/>
        <column xsi:type="varchar" name="utm_campaign" length="255" nullable="true" comment="utm_campaign"/>
        <column xsi:type="varchar" name="email_status" length="16" nullable="false" default="skip" comment="pending / sending / sent / error / skip"/>
        <column xsi:type="timestamp" name="email_sent_at" on_update="false" nullable="true" comment="Launch email sent at"/>
        <column xsi:type="text" name="email_error" nullable="true" comment="Last sending error"/>
        <column xsi:type="timestamp" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Subscribed at"/>
        <column xsi:type="timestamp" name="updated_at" on_update="true" nullable="false" default="CURRENT_TIMESTAMP" comment="Updated at"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="entity_id"/>
        </constraint>
        <constraint xsi:type="unique" referenceId="AUTOGEDAL_BLACKFRIDAY_SUBSCRIBER_EMAIL">
            <column name="email"/>
        </constraint>
        <index referenceId="AUTOGEDAL_BLACKFRIDAY_SUBSCRIBER_EMAIL_STATUS" indexType="btree">
            <column name="email_status"/>
        </index>
        <index referenceId="AUTOGEDAL_BLACKFRIDAY_SUBSCRIBER_FULLTEXT" indexType="fulltext">
            <column name="email"/>
            <column name="favorites"/>
        </index>
    </table>
</schema>
