<?xml version="1.0"?>
<!--
/**
 * @author Amasty Team
 * @copyright Copyright (c) Amasty (https://www.amasty.com)
 * @package SEO Toolkit Base 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_seotoolkit_redirect" resource="default" engine="innodb" comment="amasty_seotoolkit_redirect">
        <column xsi:type="int" name="redirect_id" padding="6" unsigned="false" nullable="false" identity="true" comment="Redirect Id"/>
        <column xsi:type="boolean" name="status" nullable="false" comment="Redirect Status"/>
        <column xsi:type="varchar" name="request_path" nullable="true" comment="Request Path"/>
        <column xsi:type="varchar" name="target_path" nullable="true" comment="Target Path"/>
        <column xsi:type="boolean" name="is_target_path_external" nullable="true" comment="Is Target Path External"/>
        <column xsi:type="smallint" name="redirect_type" padding="5" unsigned="true" nullable="false" identity="false" default="302" comment="Redirect Type"/>
        <column xsi:type="boolean" name="undefined_page_only" nullable="false" comment="Used for 404 Pages"/>
        <column xsi:type="varchar" name="description" nullable="true" comment="Description"/>
        <column xsi:type="int" name="priority" padding="11" unsigned="false" nullable="false" identity="false" default="1" comment="Priority"/>
        <column xsi:type="boolean" name="is_autogenerated" nullable="false" default="0" comment="Is Redirect Autogenerated"/>

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

        <constraint xsi:type="unique" referenceId="AMASTY_SEOTOOLKIT_REDIRECT_REDIRECT_ID">
            <column name="redirect_id"/>
        </constraint>
    </table>

    <table name="amasty_seotoolkit_redirect_expiration" resource="default" engine="innodb" comment="amasty_seotoolkit_redirect_expiration">
        <column xsi:type="int" name="redirect_id" padding="6" unsigned="false" nullable="false" identity="false" comment="Redirect Id"/>
        <column xsi:type="datetime" name="expiration_date" on_update="false" nullable="false"/>

        <constraint
            xsi:type="foreign"
            referenceId="AMASTY_SEOTOOLKIT_REDIRECT_EXPIRATION_REDIRECT_ID_AMASTY_SEOTOOLKIT_REDIRECT_REDIRECT_ID"
            table="amasty_seotoolkit_redirect_expiration"
            column="redirect_id"
            referenceTable="amasty_seotoolkit_redirect"
            referenceColumn="redirect_id"
            onDelete="CASCADE"
        />

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

    <table name="amasty_seotoolkit_redirect_store" resource="default" engine="innodb" comment="amasty_seotoolkit_redirect_store">
        <column xsi:type="int" name="redirect_id" padding="6" unsigned="false" nullable="false" identity="false" comment="Redirect 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="redirect_id"/>
            <column name="store_id"/>
        </constraint>
        <constraint xsi:type="foreign"
                    referenceId="AMASTY_SEOTOOLKIT_REDIRECT_STORE_REDIRECT_ID_AMASTY_SEOTOOLKIT_REDIRECT_REDIRECT_ID"
                    table="amasty_seotoolkit_redirect_store"
                    column="redirect_id"
                    referenceTable="amasty_seotoolkit_redirect"
                    referenceColumn="redirect_id"
                    onDelete="CASCADE"/>
        <constraint xsi:type="foreign" referenceId="AMASTY_SEOTOOLKIT_REDIRECT_STORE_STORE_ID_STORE_STORE_ID" table="amasty_seotoolkit_redirect_store" column="store_id" referenceTable="store" referenceColumn="store_id" onDelete="CASCADE"/>
    </table>
    <table name="cms_page" resource="default">
        <column xsi:type="varchar" name="robots" nullable="true" comment="Configure CMS Page Robots"/>
        <column xsi:type="varchar" name="canonical" nullable="true" comment="Configure CMS Page Canonical"/>
    </table>
</schema>
