<?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\Promotion\Model\Promotion" table="sylius_promotion">
        <id name="id" type="integer">
            <generator strategy="AUTO" />
        </id>

        <field name="code" type="string" unique="true" />
        <field name="name" type="string" />
        <field name="description" type="string" nullable="true" />
        <field name="priority" type="integer">
            <gedmo:sortable-position/>
        </field>
        <field name="exclusive" type="boolean" />
        <field name="usageLimit" column="usage_limit" type="integer" nullable="true" />
        <field name="used" type="integer" />
        <field name="couponBased" column="coupon_based" type="boolean" />
        <field name="startsAt" column="starts_at" type="datetime" nullable="true"/>
        <field name="endsAt" column="ends_at" type="datetime" nullable="true"/>
        <field name="appliesToDiscounted" column="applies_to_discounted" type="boolean">
            <options>
                <option name="default">1</option>
            </options>
        </field>
        <field name="archivedAt" column="archived_at" type="datetime" nullable="true" />

        <one-to-many field="coupons" target-entity="Sylius\Component\Promotion\Model\PromotionCouponInterface" mapped-by="promotion">
            <cascade>
                <cascade-all />
            </cascade>
            <order-by>
                <order-by-field name="id" />
            </order-by>
        </one-to-many>
        <one-to-many field="rules" target-entity="Sylius\Component\Promotion\Model\PromotionRuleInterface" mapped-by="promotion" orphan-removal="true">
            <cascade>
                <cascade-all />
            </cascade>
            <order-by>
                <order-by-field name="id" />
            </order-by>
        </one-to-many>
        <one-to-many field="actions" target-entity="Sylius\Component\Promotion\Model\PromotionActionInterface" mapped-by="promotion" orphan-removal="true">
            <cascade>
                <cascade-all />
            </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>
    </mapped-superclass>
</doctrine-mapping>
