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

    <mapped-superclass name="Sylius\Component\Product\Model\ProductVariant" table="sylius_product_variant">
        <id name="id" column="id" type="integer">
            <generator strategy="AUTO" />
        </id>

        <field name="code" column="code" type="string" unique="true"  nullable="false"/>

        <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 target-entity="Sylius\Component\Product\Model\ProductInterface" field="product" inversed-by="variants">
            <join-column name="product_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
            <gedmo:sortable-group />
        </many-to-one>

        <many-to-many target-entity="Sylius\Component\Product\Model\ProductOptionValueInterface" field="optionValues">
            <order-by>
                <order-by-field name="id" />
            </order-by>

            <join-table name="sylius_product_variant_option_value">
                <join-columns>
                    <join-column name="variant_id" referenced-column-name="id" unique="false" nullable="false" on-delete="CASCADE" />
                </join-columns>
                <inverse-join-columns>
                    <join-column name="option_value_id" referenced-column-name="id" unique="false" nullable="false" on-delete="CASCADE" />
                </inverse-join-columns>
            </join-table>
        </many-to-many>

        <field name="position" type="integer">
            <gedmo:sortable-position />
        </field>

        <field name="enabled" column="enabled" type="boolean" />
    </mapped-superclass>

</doctrine-mapping>
