<?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="liveprawn_customer_profile" resource="default" engine="innodb"
           comment="Live Prawn Customer Rewards Profile">
        <column xsi:type="int" name="entity_id" unsigned="true" nullable="false" identity="true"
                comment="Entity ID"/>
        <column xsi:type="int" name="customer_id" unsigned="true" nullable="false" comment="Customer ID"/>
        <column xsi:type="varchar" name="membership_type" length="32" nullable="false" default="free"
                comment="Membership Type"/>
        <column xsi:type="decimal" name="lifetime_spend" scale="2" precision="12" unsigned="false"
                nullable="false" default="0" comment="Lifetime Spend"/>
        <column xsi:type="varchar" name="vip_tier" length="32" nullable="false" default="none"
                comment="VIP Tier"/>
        <column xsi:type="date" name="birthday" nullable="true" comment="Birthday"/>
        <column xsi:type="timestamp" name="premium_activated_at" nullable="true" comment="Premium Activated At"/>
        <column xsi:type="varchar" name="welcome_pack_status" length="32" nullable="false"
                default="not_eligible" comment="Welcome Pack Status"/>
        <column xsi:type="int" name="welcome_pack_order_id" unsigned="true" nullable="true"
                comment="Welcome Pack Order ID"/>
        <column xsi:type="varchar" name="referral_code" length="64" nullable="true" comment="Referral Code"/>
        <column xsi:type="timestamp" name="created_at" nullable="false" default="CURRENT_TIMESTAMP"
                comment="Created At"/>
        <column xsi:type="timestamp" name="updated_at" nullable="false" default="CURRENT_TIMESTAMP"
                on_update="true" comment="Updated At"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="entity_id"/>
        </constraint>
        <constraint xsi:type="unique" referenceId="LIVEPRAWN_CUSTOMER_PROFILE_CUSTOMER_ID">
            <column name="customer_id"/>
        </constraint>
        <constraint xsi:type="unique" referenceId="LIVEPRAWN_CUSTOMER_PROFILE_REFERRAL_CODE">
            <column name="referral_code"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="LIVEPRAWN_CUSTOMER_PROFILE_CUSTOMER_ID_CUSTOMER_ENTITY"
                    table="liveprawn_customer_profile" column="customer_id"
                    referenceTable="customer_entity" referenceColumn="entity_id" onDelete="CASCADE"/>
        <index referenceId="LIVEPRAWN_CUSTOMER_PROFILE_MEMBERSHIP_TYPE" indexType="btree">
            <column name="membership_type"/>
        </index>
        <index referenceId="LIVEPRAWN_CUSTOMER_PROFILE_VIP_TIER" indexType="btree">
            <column name="vip_tier"/>
        </index>
    </table>

    <table name="liveprawn_reward_ledger" resource="default" engine="innodb"
           comment="Live Prawn Reward Ledger">
        <column xsi:type="int" name="entity_id" unsigned="true" nullable="false" identity="true"
                comment="Entity ID"/>
        <column xsi:type="int" name="customer_id" unsigned="true" nullable="false" comment="Customer ID"/>
        <column xsi:type="varchar" name="reward_type" length="64" nullable="false" comment="Reward Type"/>
        <column xsi:type="varchar" name="transaction_type" length="64" nullable="false"
                comment="Transaction Type"/>
        <column xsi:type="decimal" name="amount" scale="2" precision="12" nullable="true" comment="Amount"/>
        <column xsi:type="decimal" name="points" scale="2" precision="12" nullable="true" comment="Points"/>
        <column xsi:type="varchar" name="source_type" length="64" nullable="true" comment="Source Type"/>
        <column xsi:type="varchar" name="source_id" length="64" nullable="true" comment="Source ID"/>
        <column xsi:type="text" name="description" nullable="true" comment="Description"/>
        <column xsi:type="varchar" name="status" length="32" nullable="false" default="pending"
                comment="Status"/>
        <column xsi:type="timestamp" name="expires_at" nullable="true" comment="Expires At"/>
        <column xsi:type="timestamp" name="created_at" nullable="false" default="CURRENT_TIMESTAMP"
                comment="Created At"/>
        <column xsi:type="timestamp" name="updated_at" nullable="false" default="CURRENT_TIMESTAMP"
                on_update="true" comment="Updated At"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="entity_id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="LIVEPRAWN_REWARD_LEDGER_CUSTOMER_ID_CUSTOMER_ENTITY"
                    table="liveprawn_reward_ledger" column="customer_id"
                    referenceTable="customer_entity" referenceColumn="entity_id" onDelete="CASCADE"/>
        <index referenceId="LIVEPRAWN_REWARD_LEDGER_CUSTOMER_ID" indexType="btree">
            <column name="customer_id"/>
        </index>
        <index referenceId="LIVEPRAWN_REWARD_LEDGER_STATUS" indexType="btree">
            <column name="status"/>
        </index>
        <index referenceId="LIVEPRAWN_REWARD_LEDGER_REWARD_TYPE" indexType="btree">
            <column name="reward_type"/>
        </index>
    </table>

    <table name="liveprawn_referral" resource="default" engine="innodb"
           comment="Live Prawn Referral">
        <column xsi:type="int" name="entity_id" unsigned="true" nullable="false" identity="true"
                comment="Entity ID"/>
        <column xsi:type="int" name="referrer_customer_id" unsigned="true" nullable="true"
                comment="Referrer Customer ID"/>
        <column xsi:type="int" name="referred_customer_id" unsigned="true" nullable="true"
                comment="Referred Customer ID"/>
        <column xsi:type="varchar" name="referral_code" length="64" nullable="false" comment="Referral Code"/>
        <column xsi:type="varchar" name="status" length="32" nullable="false" default="pending"
                comment="Status"/>
        <column xsi:type="int" name="first_paid_order_id" unsigned="true" nullable="true"
                comment="First Paid Order ID"/>
        <column xsi:type="int" name="reward_ledger_id" unsigned="true" nullable="true"
                comment="Reward Ledger ID"/>
        <column xsi:type="timestamp" name="created_at" nullable="false" default="CURRENT_TIMESTAMP"
                comment="Created At"/>
        <column xsi:type="timestamp" name="updated_at" nullable="false" default="CURRENT_TIMESTAMP"
                on_update="true" comment="Updated At"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="entity_id"/>
        </constraint>
        <index referenceId="LIVEPRAWN_REFERRAL_REFERRAL_CODE" indexType="btree">
            <column name="referral_code"/>
        </index>
        <index referenceId="LIVEPRAWN_REFERRAL_REFERRER_CUSTOMER_ID" indexType="btree">
            <column name="referrer_customer_id"/>
        </index>
        <index referenceId="LIVEPRAWN_REFERRAL_REFERRED_CUSTOMER_ID" indexType="btree">
            <column name="referred_customer_id"/>
        </index>
        <index referenceId="LIVEPRAWN_REFERRAL_STATUS" indexType="btree">
            <column name="status"/>
        </index>
    </table>

    <table name="liveprawn_restaurant_assignment" resource="default" engine="innodb"
           comment="Live Prawn Restaurant Introducer Assignment">
        <column xsi:type="int" name="entity_id" unsigned="true" nullable="false" identity="true"
                comment="Entity ID"/>
        <column xsi:type="int" name="restaurant_customer_id" unsigned="true" nullable="false"
                comment="Restaurant Customer ID"/>
        <column xsi:type="varchar" name="restaurant_company_name" length="255" nullable="true"
                comment="Restaurant Company Name"/>
        <column xsi:type="varchar" name="introducer_type" length="32" nullable="false"
                comment="Introducer Type"/>
        <column xsi:type="int" name="introducer_customer_id" unsigned="true" nullable="true"
                comment="Introducer Customer ID"/>
        <column xsi:type="int" name="introducer_admin_user_id" unsigned="true" nullable="true"
                comment="Introducer Admin User ID"/>
        <column xsi:type="varchar" name="introducer_name_snapshot" length="255" nullable="true"
                comment="Introducer Name Snapshot"/>
        <column xsi:type="varchar" name="commission_type" length="32" nullable="false" default="percentage"
                comment="Commission Type"/>
        <column xsi:type="decimal" name="commission_value" scale="4" precision="12" unsigned="false"
                nullable="false" default="0" comment="Commission Value"/>
        <column xsi:type="varchar" name="status" length="32" nullable="false" default="active"
                comment="Status"/>
        <column xsi:type="date" name="start_date" nullable="true" comment="Start Date"/>
        <column xsi:type="date" name="end_date" nullable="true" comment="End Date"/>
        <column xsi:type="text" name="notes" nullable="true" comment="Notes"/>
        <column xsi:type="int" name="created_by_admin_user_id" unsigned="true" nullable="true"
                comment="Created By Admin User ID"/>
        <column xsi:type="timestamp" name="created_at" nullable="false" default="CURRENT_TIMESTAMP"
                comment="Created At"/>
        <column xsi:type="timestamp" name="updated_at" nullable="false" default="CURRENT_TIMESTAMP"
                on_update="true" comment="Updated At"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="entity_id"/>
        </constraint>
        <constraint xsi:type="foreign"
                    referenceId="LIVEPRAWN_RESTAURANT_ASSIGNMENT_RESTAURANT_CUSTOMER_ID"
                    table="liveprawn_restaurant_assignment" column="restaurant_customer_id"
                    referenceTable="customer_entity" referenceColumn="entity_id" onDelete="CASCADE"/>
        <index referenceId="LIVEPRAWN_RESTAURANT_ASSIGNMENT_RESTAURANT_CUSTOMER_ID" indexType="btree">
            <column name="restaurant_customer_id"/>
        </index>
        <index referenceId="LIVEPRAWN_RESTAURANT_ASSIGNMENT_STATUS" indexType="btree">
            <column name="status"/>
        </index>
        <index referenceId="LIVEPRAWN_RESTAURANT_ASSIGNMENT_INTRODUCER_TYPE" indexType="btree">
            <column name="introducer_type"/>
        </index>
    </table>

    <table name="liveprawn_restaurant_commission" resource="default" engine="innodb"
           comment="Live Prawn Restaurant Introducer Commission">
        <column xsi:type="int" name="entity_id" unsigned="true" nullable="false" identity="true"
                comment="Entity ID"/>
        <column xsi:type="int" name="assignment_id" unsigned="true" nullable="false"
                comment="Assignment ID"/>
        <column xsi:type="int" name="restaurant_customer_id" unsigned="true" nullable="false"
                comment="Restaurant Customer ID"/>
        <column xsi:type="varchar" name="introducer_type" length="32" nullable="false"
                comment="Introducer Type"/>
        <column xsi:type="int" name="introducer_customer_id" unsigned="true" nullable="true"
                comment="Introducer Customer ID"/>
        <column xsi:type="int" name="introducer_admin_user_id" unsigned="true" nullable="true"
                comment="Introducer Admin User ID"/>
        <column xsi:type="int" name="order_id" unsigned="true" nullable="false" comment="Order ID"/>
        <column xsi:type="varchar" name="order_increment_id" length="32" nullable="false"
                comment="Order Increment ID"/>
        <column xsi:type="decimal" name="order_subtotal" scale="2" precision="12" unsigned="false"
                nullable="false" default="0" comment="Order Subtotal"/>
        <column xsi:type="varchar" name="commission_type" length="32" nullable="false"
                comment="Commission Type"/>
        <column xsi:type="decimal" name="commission_value" scale="4" precision="12" unsigned="false"
                nullable="false" default="0" comment="Commission Value"/>
        <column xsi:type="decimal" name="commission_amount" scale="2" precision="12" unsigned="false"
                nullable="false" default="0" comment="Commission Amount"/>
        <column xsi:type="varchar" name="status" length="32" nullable="false" default="pending"
                comment="Status"/>
        <column xsi:type="timestamp" name="calculated_at" nullable="false" default="CURRENT_TIMESTAMP"
                comment="Calculated At"/>
        <column xsi:type="int" name="approved_by_admin_user_id" unsigned="true" nullable="true"
                comment="Approved By Admin User ID"/>
        <column xsi:type="timestamp" name="paid_at" nullable="true" comment="Paid At"/>
        <column xsi:type="text" name="notes" nullable="true" comment="Notes"/>
        <column xsi:type="timestamp" name="created_at" nullable="false" default="CURRENT_TIMESTAMP"
                comment="Created At"/>
        <column xsi:type="timestamp" name="updated_at" nullable="false" default="CURRENT_TIMESTAMP"
                on_update="true" comment="Updated At"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="entity_id"/>
        </constraint>
        <constraint xsi:type="unique" referenceId="LIVEPRAWN_RESTAURANT_COMMISSION_ORDER_ID">
            <column name="order_id"/>
        </constraint>
        <constraint xsi:type="foreign"
                    referenceId="LIVEPRAWN_RESTAURANT_COMMISSION_ASSIGNMENT_ID"
                    table="liveprawn_restaurant_commission" column="assignment_id"
                    referenceTable="liveprawn_restaurant_assignment" referenceColumn="entity_id"
                    onDelete="CASCADE"/>
        <constraint xsi:type="foreign"
                    referenceId="LIVEPRAWN_RESTAURANT_COMMISSION_RESTAURANT_CUSTOMER_ID"
                    table="liveprawn_restaurant_commission" column="restaurant_customer_id"
                    referenceTable="customer_entity" referenceColumn="entity_id" onDelete="CASCADE"/>
        <index referenceId="LIVEPRAWN_RESTAURANT_COMMISSION_STATUS" indexType="btree">
            <column name="status"/>
        </index>
        <index referenceId="LIVEPRAWN_RESTAURANT_COMMISSION_RESTAURANT_CUSTOMER_ID" indexType="btree">
            <column name="restaurant_customer_id"/>
        </index>
    </table>
</schema>
