<?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:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping">

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

        <many-to-one field="method" target-entity="Sylius\Component\Shipping\Model\ShippingMethodInterface">
            <join-column name="method_id" referenced-column-name="id" nullable="false" />
        </many-to-one>

        <field name="state" column="state" type="string" nullable="false" />
        <field name="tracking" column="tracking" type="string" nullable="true" />

        <one-to-many field="units" target-entity="Sylius\Component\Shipping\Model\ShipmentUnitInterface" mapped-by="shipment" orphan-removal="false">
            <cascade>
                <cascade-persist/>
            </cascade>
            <order-by>
                <order-by-field name="id" />
            </order-by>
        </one-to-many>

        <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="shippedAt" column="shipped_at" type="datetime" nullable="true" />
    </mapped-superclass>

</doctrine-mapping>
