<?xml version="1.0"?>
<!--
/**
 * Copyright © Klarna Bank AB (publ)
 *
 * For the full copyright and license information, please view the NOTICE
 * and LICENSE files that were distributed with this source code.
 */
-->
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <table name="klarna_payments_quote" resource="default" engine="innodb" comment="Klarna Payments Quote">
        <column name="payments_quote_id" xsi:type="int" padding="10" unsigned="true" nullable="false" identity="true"
                comment="Payments Id"/>
        <column name="session_id" xsi:type="varchar" length="255" nullable="true" comment="Klarna Session Id"/>
        <column name="client_token" xsi:type="text" nullable="true" comment="Klarna Client Token"/>
        <column name="authorization_token" xsi:type="varchar" length="255" nullable="true"
                comment="Authorization Token"/>
        <column name="is_active" xsi:type="smallint" padding="6" unsigned="false" nullable="false" identity="false"
                default="0" comment="Is Active"/>
        <column name="quote_id" xsi:type="int" padding="10" unsigned="true" nullable="false" identity="false"
                comment="Quote Id"/>
        <column name="payment_methods" xsi:type="varchar" length="255" nullable="true"
                comment="Payment Method Categories"/>
        <column name="payment_method_info" xsi:type="text" nullable="true" comment="Payment Method Category Info"/>
        <column name="customer_type" xsi:type="varchar" length="12" nullable="true" comment="Customer Type"/>
        <column name="order_id" xsi:type="int" unsigned="true" nullable="true" identity="false"
                comment="Order Id"/>
        <column name="redirect_url" xsi:type="varchar" nullable="false" length="255" default=""
                comment="Redirect url"/>
        <column name="auth_callback_token" xsi:type="varchar" nullable="false" length="255" default=""
                comment="Authorization callback token"/>
        <column name="is_auth_callback_active" xsi:type="smallint" padding="6" unsigned="false" nullable="false" identity="false"
                default="0" comment="Indicating if the authorization callback is currently running"/>
        <column name="is_kec_session" xsi:type="smallint" padding="6" unsigned="false" nullable="false" identity="false"
                default="0" comment="Is KEC session"/>
        <column name="request_data" xsi:type="text" nullable="true" comment="Latest data used to update KP session"/>
        <column name="created_at" xsi:type="timestamp" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Created At"/>
        <column name="updated_at" xsi:type="timestamp" on_update="true" nullable="false" default="CURRENT_TIMESTAMP" comment="Updated At"/>

        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="payments_quote_id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="QUOTE_ID_KLARNA_PAYMENTS_QUOTE_QUOTE_ID_QUOTE_ENTITY_ID"
            table="klarna_payments_quote"
            column="quote_id"
            referenceTable="quote"
            referenceColumn="entity_id"
            onDelete="CASCADE"
        />
        <index referenceId="KLARNA_PAYMENTS_QUOTE_QUOTE_ID" indexType="btree">
            <column name="quote_id"/>
        </index>
        <index referenceId="KLARNA_PAYMENTS_QUOTE_SESSION_ID" indexType="btree">
            <column name="session_id"/>
        </index>
        <index referenceId="KLARNA_PAYMENTS_QUOTE_ORDER_ID" indexType="btree">
            <column name="order_id"/>
        </index>
        <index referenceId="KLARNA_PAYMENTS_QUOTE_AUTHORIZATION_TOKEN" indexType="btree">
            <column name="authorization_token"/>
        </index>
    </table>
</schema>
