<?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\ChannelPricing" table="sylius_channel_pricing">
        <unique-constraints>
            <unique-constraint columns="product_variant_id,channel_code" name="product_variant_channel_idx" />
        </unique-constraints>

        <id name="id" column="id" type="integer">
            <generator strategy="AUTO" />
        </id>
        <field name="price" column="price" type="integer" nullable="true" />
        <field name="originalPrice" column="original_price" type="integer" nullable="true" />
        <field name="minimumPrice" column="minimum_price" type="integer" nullable="true">
            <options>
                <option name="default">0</option>
            </options>
        </field>
        <field name="lowestPriceBeforeDiscount" column="lowest_price_before_discount" type="integer" nullable="true" />
        <field name="channelCode" column="channel_code" type="string" />
        <many-to-many field="appliedPromotions" target-entity="Sylius\Component\Promotion\Model\CatalogPromotionInterface">
            <order-by>
                <order-by-field name="id" />
            </order-by>

            <join-table name="sylius_channel_pricing_catalog_promotions">
                <join-columns>
                    <join-column name="channel_pricing_id" nullable="false"/>
                </join-columns>
                <inverse-join-columns>
                    <join-column name="catalog_promotion_id" nullable="false"/>
                </inverse-join-columns>
            </join-table>
        </many-to-many>

        <many-to-one field="productVariant" target-entity="Sylius\Component\Product\Model\ProductVariantInterface" inversed-by="channelPricings">
            <join-column name="product_variant_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
            <cascade>
                <cascade-persist />
            </cascade>
        </many-to-one>
    </mapped-superclass>

</doctrine-mapping>
