<?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_promo_rule_config" resource="default" engine="innodb" comment="Autogedal Promo Rule Config">
        <column xsi:type="int" name="config_id" padding="10" unsigned="true" nullable="false" identity="true" comment="Config ID"/>
        <column xsi:type="int" name="rule_id" padding="10" unsigned="true" nullable="false" comment="Rule ID"/>
        <column xsi:type="smallint" name="restrict_once_per_email" nullable="false" default="0" comment="Restrict Once Per Email"/>
        <column xsi:type="varchar" name="block_discount_scope" nullable="false" length="32" default="none" comment="Discount Blocking Scope"/>
        <column xsi:type="text" name="additional_policy_flags" nullable="true" comment="Additional Policy Flags"/>
        <column xsi:type="timestamp" name="created_at" nullable="true" comment="Created At"/>
        <column xsi:type="timestamp" name="updated_at" nullable="true" comment="Updated At"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="config_id"/>
        </constraint>
        <constraint xsi:type="unique" referenceId="AUTOGEDAL_PROMO_RULE_CONFIG_RULE_ID_UNQ">
            <column name="rule_id"/>
        </constraint>
        <index referenceId="AUTOGEDAL_PROMO_RULE_CONFIG_BLOCK_DISCOUNT_SCOPE_IDX">
            <column name="block_discount_scope"/>
        </index>
    </table>
    <table name="autogedal_promo_rule_usage" resource="default" engine="innodb" comment="Autogedal Promo Rule Usage">
        <column xsi:type="bigint" name="usage_id" unsigned="true" nullable="false" identity="true" comment="Usage ID"/>
        <column xsi:type="int" name="rule_id" padding="10" unsigned="true" nullable="false" comment="Rule ID"/>
        <column xsi:type="int" name="coupon_id" padding="10" unsigned="true" nullable="true" comment="Coupon ID"/>
        <column xsi:type="varchar" name="normalized_email" nullable="false" length="255" comment="Normalized Email"/>
        <column xsi:type="int" name="times_used" padding="10" unsigned="true" nullable="false" default="1" comment="Times Used"/>
        <column xsi:type="timestamp" name="created_at" nullable="true" comment="Created At"/>
        <column xsi:type="timestamp" name="updated_at" nullable="true" comment="Updated At"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="usage_id"/>
        </constraint>
        <constraint xsi:type="unique" referenceId="AUTOGEDAL_PROMO_RULE_USAGE_RULE_EMAIL_UNQ">
            <column name="rule_id"/>
            <column name="normalized_email"/>
        </constraint>
        <index referenceId="AUTOGEDAL_PROMO_RULE_USAGE_EMAIL_IDX">
            <column name="normalized_email"/>
        </index>
        <index referenceId="AUTOGEDAL_PROMO_RULE_USAGE_RULE_ID_IDX">
            <column name="rule_id"/>
        </index>
        <index referenceId="AUTOGEDAL_PROMO_RULE_USAGE_COUPON_ID_IDX">
            <column name="coupon_id"/>
        </index>
    </table>
</schema>
