<?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\Adjustment" table="sylius_adjustment">
        <id name="id" column="id" type="integer">
            <generator strategy="AUTO" />
        </id>

        <field name="type" column="type" type="string" />
        <field name="label" column="label" type="string" nullable="true" />
        <field name="amount" column="amount" type="integer" />
        <field name="neutral" column="is_neutral" type="boolean" />
        <field name="locked" column="is_locked" type="boolean" />
        <field name="originCode" column="origin_code" type="string" nullable="true" />
        <field name="details" type="json" />

        <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>

        <many-to-one field="order" target-entity="Sylius\Component\Order\Model\OrderInterface" inversed-by="adjustments">
            <join-column name="order_id" referenced-column-name="id" nullable="true" on-delete="CASCADE"/>
        </many-to-one>

        <many-to-one field="orderItem" target-entity="Sylius\Component\Order\Model\OrderItemInterface" inversed-by="adjustments">
            <join-column name="order_item_id" referenced-column-name="id" nullable="true" on-delete="CASCADE"/>
        </many-to-one>

        <many-to-one field="orderItemUnit" target-entity="Sylius\Component\Order\Model\OrderItemUnitInterface" inversed-by="adjustments">
            <join-column name="order_item_unit_id" referenced-column-name="id" nullable="true" on-delete="CASCADE"/>
        </many-to-one>
    </mapped-superclass>

</doctrine-mapping>
