<?xml version="1.0"?>
<!--
/**
 * @author Amasty Team
 * @copyright Copyright (c) Amasty (https://www.amasty.com)
 * @package Advanced Product Reviews 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_advanced_review_images" resource="default" engine="innodb"
           comment="Amasty Advanced Reviews Images Table">
        <column xsi:type="int" name="image_id" padding="10" unsigned="true" nullable="false" identity="true"
                comment="Review Id"/>
        <column xsi:type="bigint" name="review_id" padding="20" unsigned="true" nullable="false" identity="false"
                onCreate="migrateDataFrom(review_id)" comment="Review ID"/>
        <column xsi:type="mediumtext" name="path" nullable="true" comment="Image path"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="image_id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="AMASTY_ADVANCED_REVIEW_IMAGES_REVIEW_ID_REVIEW_REVIEW_ID"
                    table="amasty_advanced_review_images"
                    column="review_id"
                    referenceTable="review"
                    referenceColumn="review_id"
                    onDelete="CASCADE"/>
    </table>
    <table name="amasty_advanced_review_vote" resource="default" engine="innodb"
           comment="Amasty Advanced Reviews Vote Table">
        <column xsi:type="int" name="vote_id" padding="10" unsigned="true" nullable="false" identity="true"
                comment="Vote Id"/>
        <column xsi:type="bigint" name="review_id" padding="20" unsigned="true" nullable="false" identity="false"
                onCreate="migrateDataFrom(review_id)" default="0" comment="Review table id"/>
        <column xsi:type="smallint" name="type" padding="6" unsigned="false" nullable="true" identity="false"
                comment="Type"/>
        <column xsi:type="text" name="ip" nullable="true" comment="ip"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="vote_id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="AMASTY_ADVANCED_REVIEW_VOTE_REVIEW_ID_REVIEW_REVIEW_ID"
                    table="amasty_advanced_review_vote"
                    column="review_id"
                    referenceTable="review"
                    referenceColumn="review_id"
                    onDelete="CASCADE"/>
    </table>
    <table name="review" resource="default">
        <column xsi:type="text" name="answer" nullable="true" comment="Admin answer"/>
        <column xsi:type="smallint" name="verified_buyer" padding="6" unsigned="false" nullable="true" identity="false"
                default="0" comment="Verified Buyer"/>
        <column xsi:type="smallint" name="is_recommended" padding="6" unsigned="false" nullable="true" identity="false"
                default="0" comment="Is Recommended"/>
        <column xsi:type="smallint" name="amasty_admin_answer_account_only" padding="6" unsigned="false" nullable="true"
                identity="false" comment="Is Admin Answer Visible On Account Area Only"/>
    </table>
    <table name="amasty_advanced_review_reminder" resource="default" engine="innodb"
           comment="Amasty Advanced Reviews Reminder Table">
        <column xsi:type="int" name="entity_id" padding="10" unsigned="true" nullable="false" identity="true"
                comment="Entity Id"/>
        <column xsi:type="int" name="order_id" padding="10" unsigned="true" nullable="false" identity="false"
                default="0" comment="Order id"/>
        <column xsi:type="timestamp" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP"
                comment="Created At"/>
        <column xsi:type="timestamp" name="updated_at" on_update="true" nullable="false" default="CURRENT_TIMESTAMP"
                comment="Updated At"/>
        <column xsi:type="timestamp" name="send_date" on_update="false" nullable="true" comment="Send Date"/>
        <column xsi:type="int" name="status" padding="11" unsigned="false" nullable="false" identity="false" default="0"
                comment="Status"/>
        <column xsi:type="boolean" name="coupon" nullable="true" comment="is Coupon Sent"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="entity_id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="AMASTY_ADVANCED_REVIEW_RMNDR_ORDER_ID_SALES_ORDER_ORD_ID"
                    table="amasty_advanced_review_reminder"
                    column="order_id"
                    referenceTable="sales_order"
                    referenceColumn="entity_id"
                    onDelete="CASCADE"/>
        <constraint xsi:type="unique" referenceId="AMASTY_ADVANCED_REVIEW_REMINDER_ENTITY_ID_ORDER_ID">
            <column name="entity_id"/>
            <column name="order_id"/>
        </constraint>
        <index referenceId="AMASTY_ADVANCED_REVIEW_REMINDER_ORDER_ID" indexType="btree">
            <column name="order_id"/>
        </index>
    </table>
    <table name="amasty_advanced_review_unsubscribe" resource="default" engine="innodb"
           comment="Amasty Advanced Reviews Reminder Unsubscribe Table">
        <column xsi:type="int" name="entity_id" padding="10" unsigned="true" nullable="false" identity="true"
                comment="Entity Id"/>
        <column xsi:type="timestamp" name="unsubscribed_at" on_update="false" nullable="false"
                default="CURRENT_TIMESTAMP" comment="Unsubscribed At"/>
        <column xsi:type="text" name="email" nullable="false" comment="Email"/>
        <column xsi:type="boolean" name="isComment" nullable="true" comment="Unsubscribe Type"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
              <column name="entity_id"/>
        </constraint>
    </table>
    <table name="review_detail" resource="default">
        <column xsi:type="text" name="like_about" nullable="true" comment="Customer Like About This Product"/>
        <column xsi:type="text" name="not_like_about" nullable="true"
                comment="Customer Do Not Like About This Product"/>
        <column xsi:type="text" name="guest_email" nullable="true" comment="Guest Email"/>
    </table>
    <table name="amasty_advanced_review_reminder_product" resource="default" engine="innodb"
           comment="Amasty Advanced Reviews Reminder Product Table">
        <column xsi:type="varchar" name="customer_email" nullable="false" length="255" comment="Customer Email"/>
        <column xsi:type="int" name="product_id" padding="10" unsigned="true" nullable="false" identity="false"
                comment="Product Id"/>
        <constraint xsi:type="foreign" referenceId="AMASTY_ADVANCED_REVIEW_REMINDER_PRD_PRD_ID_CAT_PRD_ENT_PRD_ID"
                    table="amasty_advanced_review_reminder_product"
                    column="product_id"
                    referenceTable="catalog_product_entity"
                    referenceColumn="entity_id"
                    onDelete="CASCADE"/>
        <constraint xsi:type="unique" referenceId="AMASTY_ADVANCED_REVIEW_REMINDER_PRD_CSTR_EMAIL_PRD_ID">
            <column name="customer_email"/>
            <column name="product_id"/>
        </constraint>
    </table>
    <table name="amasty_advanced_review_comments" resource="default" engine="innodb"
           comment="Amasty Advanced Reviews Comments Table">
        <column xsi:type="int" name="id" padding="10" unsigned="true" nullable="false" identity="true"
                comment="Comment Id"/>
        <column xsi:type="bigint" name="review_id" padding="20" unsigned="true" nullable="false" identity="false"
                comment="Review Id"/>
        <column xsi:type="smallint" name="store_id" padding="5" unsigned="true" nullable="false" identity="false"
                comment="Store Id"/>
        <column xsi:type="smallint" name="status" padding="5" unsigned="true" nullable="false" identity="false"
                comment="Status"/>
        <column xsi:type="int" name="customer_id" padding="10" unsigned="true" nullable="true" identity="false"
                comment="Customer Id"/>
        <column xsi:type="text" name="message" nullable="true" comment="Message"/>
        <column xsi:type="varchar" name="nickname" nullable="true" length="255" comment="Nickname"/>
        <column xsi:type="varchar" name="email" nullable="true" length="255" comment="Email"/>
        <column xsi:type="varchar" name="session_id" nullable="true" length="255" comment="Session Id"/>
        <column xsi:type="timestamp" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP"
                comment="Created 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="id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="AMASTY_ADVANCED_REVIEW_COMMENTS_REVIEW_ID_REVIEW_REVIEW_ID"
                    table="amasty_advanced_review_comments"
                    column="review_id"
                    referenceTable="review"
                    referenceColumn="review_id"
                    onDelete="CASCADE"/>
    </table>
</schema>
