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

<!--

 This file is part of the Sylius package.

 (c) Paweł Jędrzejewski

 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">
        <id name="id" column="id" type="integer">
            <generator strategy="AUTO" />
        </id>

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

        <field name="state" column="state" type="string" />
        <field name="completedAt" column="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>

            <gedmo:versioned />
        </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>
        </one-to-many>

        <one-to-many field="comments" target-entity="Sylius\Component\Order\Model\CommentInterface" mapped-by="order" orphan-removal="true">
            <cascade>
                <cascade-all/>
            </cascade>
        </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>
        <field name="deletedAt" column="deleted_at" type="datetime" nullable="true" />

        <gedmo:soft-deleteable field-name="deletedAt" />
        <gedmo:loggable />
    </mapped-superclass>

</doctrine-mapping>
