<?xml version="1.0"?>
<!--
/**
 * @author Amasty Team
 * @copyright Copyright (c) 2023 Amasty (https://www.amasty.com)
 * @package Login as Customer 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_customer_login_log" resource="default" engine="innodb" comment="Amasty Admin Login as Customer Log table">
    <column xsi:type="int" name="logged_in_id" padding="10" unsigned="true" nullable="false" identity="true" comment="Log Id"/>
    <column xsi:type="timestamp" name="logged_in_time" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Login date"/>
    <column xsi:type="int" name="admin_id" padding="10" unsigned="true" nullable="true" identity="false" comment="Logged In Admin ID"/>
    <column xsi:type="varchar" name="admin_username" nullable="true" length="40" comment="Logged In Admin Username"/>
    <column xsi:type="varchar" name="admin_email" nullable="true" length="128" comment="Logged In Admin Email"/>
    <column xsi:type="int" name="customer_id" padding="10" unsigned="true" nullable="true" identity="false" comment="Logged In Customer ID"/>
    <column xsi:type="varchar" name="customer_name" nullable="true" length="255" comment="Logged In Customer Name"/>
    <column xsi:type="varchar" name="customer_lastname" nullable="true" length="255" comment="Logged In Customer LastName"/>
    <column xsi:type="varchar" name="customer_email" nullable="true" length="255" comment="Logged In Customer Email"/>
    <column xsi:type="smallint" name="website_id" padding="5" unsigned="true" nullable="true" identity="false" comment="Logged In Website ID"/>
    <column xsi:type="varchar" name="website_code" nullable="true" length="32" comment="Logged In Website Code"/>
    <column xsi:type="varchar" name="secret_key" nullable="true" length="32" comment="Logged In Secret Key"/>
    <column xsi:type="smallint" name="store_id" padding="5" unsigned="true" nullable="false" identity="false" comment="Logged In Store ID"/>
    <constraint xsi:type="primary" referenceId="PRIMARY">
      <column name="logged_in_id"/>
    </constraint>
    <constraint xsi:type="foreign" referenceId="AMASTY_CUSTOMER_LOGIN_LOG_ADMIN_ID_ADMIN_USER_USER_ID" table="amasty_customer_login_log" column="admin_id" referenceTable="admin_user" referenceColumn="user_id" onDelete="SET NULL"/>
    <constraint xsi:type="foreign" referenceId="AMASTY_CUSTOMER_LOGIN_LOG_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID" table="amasty_customer_login_log" column="customer_id" referenceTable="customer_entity" referenceColumn="entity_id" onDelete="SET NULL"/>
    <constraint xsi:type="foreign" referenceId="AMASTY_CUSTOMER_LOGIN_LOG_WEBSITE_ID_STORE_WEBSITE_WEBSITE_ID" table="amasty_customer_login_log" column="website_id" referenceTable="store_website" referenceColumn="website_id" onDelete="SET NULL"/>
  </table>
  <table name="amasty_customer_login_order" resource="default" engine="innodb" comment="Amasty Admin Login as Customer Order table">
    <column xsi:type="int" name="id" padding="10" unsigned="true" nullable="false" identity="true" comment="Id"/>
    <column xsi:type="int" name="order_id" padding="10" unsigned="true" nullable="false" identity="false" comment="Order ID"/>
    <column xsi:type="int" name="admin_id" padding="10" unsigned="true" nullable="false" identity="false" comment="Admin ID"/>
    <constraint xsi:type="primary" referenceId="PRIMARY">
      <column name="id"/>
    </constraint>
    <constraint xsi:type="foreign" referenceId="AMASTY_CUSTOMER_LOGIN_ORDER_ORDER_ID_SALES_ORDER_ENTITY_ID" table="amasty_customer_login_order" column="order_id" referenceTable="sales_order" referenceColumn="entity_id" onDelete="CASCADE"/>
    <constraint xsi:type="foreign" referenceId="AMASTY_CUSTOMER_LOGIN_ORDER_ADMIN_ID_ADMIN_USER_USER_ID" table="amasty_customer_login_order" column="admin_id" referenceTable="admin_user" referenceColumn="user_id" onDelete="CASCADE"/>
  </table>
</schema>
