<?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" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <mapped-superclass name="Sylius\Component\Core\Model\ProductVariant" table="sylius_product_variant">
        <field name="version" type="integer" version="true" />

        <field name="onHold" column="on_hold" type="integer" />
        <field name="onHand" column="on_hand" type="integer" />
        <field name="tracked" type="boolean" />
        <field name="width" column="width" type="float" nullable="true" />
        <field name="height" column="height" type="float" nullable="true" />
        <field name="depth" column="depth" type="float" nullable="true" />
        <field name="weight" column="weight" type="float" nullable="true" />
        <field name="shippingRequired" column="shipping_required" type="boolean" />

        <many-to-one field="taxCategory" target-entity="Sylius\Component\Taxation\Model\TaxCategoryInterface">
            <join-column name="tax_category_id" referenced-column-name="id" nullable="true" on-delete="SET NULL" />
        </many-to-one>

        <many-to-one field="shippingCategory" target-entity="Sylius\Component\Shipping\Model\ShippingCategoryInterface">
            <join-column name="shipping_category_id" referenced-column-name="id" nullable="true" on-delete="SET NULL" />
        </many-to-one>

        <one-to-many
            field="channelPricings"
            target-entity="Sylius\Component\Core\Model\ChannelPricingInterface"
            mapped-by="productVariant"
            orphan-removal="true"
            index-by="channelCode"
        >
            <order-by>
                <order-by-field name="id" />
            </order-by>

            <cascade>
                <cascade-all/>
            </cascade>
        </one-to-many>
        <many-to-many
            field="images"
            target-entity="Sylius\Component\Core\Model\ProductImageInterface"
            mapped-by="productVariants"
        >
            <order-by>
                <order-by-field name="id" />
            </order-by>

            <cascade>
                <cascade-persist/>
            </cascade>
        </many-to-many>
    </mapped-superclass>
</doctrine-mapping>
