<?xml version="1.0" encoding="UTF-8"?>

<!--

 This file is part of the Sylius package.

 (c) Sylius Sp. z o.o.

 For the full copyright and license information, please view the LICENSE
 file that was distributed with this source code.

-->

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                                      http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <mapped-superclass name="Sylius\Component\Order\Model\Order" table="sylius_order">
        <id name="id" column="id" type="integer">
            <generator strategy="AUTO" />
        </id>

        <field name="number" column="number" type="string" unique="true" nullable="true" />

        <field name="notes" column="notes" type="text" nullable="true" />

        <field name="state" column="state" type="string" />
        <field name="checkoutCompletedAt" column="checkout_completed_at" type="datetime" nullable="true" />

        <one-to-many field="items" target-entity="Sylius\Component\Order\Model\OrderItemInterface" mapped-by="order" orphan-removal="true">
            <cascade>
                <cascade-all/>
            </cascade>
            <order-by>
                <order-by-field name="id" />
            </order-by>
        </one-to-many>

        <one-to-many field="adjustments" target-entity="Sylius\Component\Order\Model\AdjustmentInterface" mapped-by="order" orphan-removal="true">
            <cascade>
                <cascade-all/>
            </cascade>
            <order-by>
                <order-by-field name="id" />
            </order-by>
        </one-to-many>

        <field name="itemsTotal" column="items_total" type="integer" />
        <field name="adjustmentsTotal" column="adjustments_total" type="integer" />
        <field name="total" column="total" type="integer" />

        <field name="createdAt" column="created_at" type="datetime">
            <gedmo:timestampable on="create"/>
        </field>
        <field name="updatedAt" column="updated_at" type="datetime" nullable="true">
            <gedmo:timestampable on="update"/>
        </field>

        <indexes>
            <index columns="state,updated_at"/>
        </indexes>
    </mapped-superclass>

</doctrine-mapping>
