<?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"
                  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\Taxonomy\Model\Taxon" table="sylius_taxon">
        <id name="id" column="id" type="integer">
            <generator strategy="AUTO" />
        </id>

        <many-to-one field="root" target-entity="Sylius\Component\Taxonomy\Model\TaxonInterface">
            <join-column name="tree_root" referenced-column-name="id" nullable="true" on-delete="CASCADE" />
            <gedmo:tree-root />
        </many-to-one>
        <many-to-one field="parent" target-entity="Sylius\Component\Taxonomy\Model\TaxonInterface" inversed-by="children">
            <join-column name="parent_id" referenced-column-name="id" nullable="true" on-delete="CASCADE" />
            <gedmo:tree-parent />
            <gedmo:sortable-group />
        </many-to-one>

        <one-to-many field="children" target-entity="Sylius\Component\Taxonomy\Model\TaxonInterface" mapped-by="parent">
            <cascade>
                <cascade-persist />
            </cascade>
            <order-by>
                <order-by-field name="position" />
                <order-by-field name="id" />
            </order-by>
        </one-to-many>

        <field name="code" column="code" type="string" unique="true" />
        <field name="left" column="tree_left" type="integer">
            <gedmo:tree-left />
        </field>
        <field name="right" column="tree_right" type="integer">
            <gedmo:tree-right />
        </field>
        <field name="level" column="tree_level" type="integer">
            <gedmo:tree-level />
        </field>
        <field name="position" type="integer">
            <gedmo:sortable-position />
        </field>

        <gedmo:tree type="nested" />

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

</doctrine-mapping>
