<?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\Channel" table="sylius_channel">
        <field name="themeName" column="theme_name" type="string" nullable="true" />
        <field name="taxCalculationStrategy" column="tax_calculation_strategy" type="string" />
        <field name="contactEmail" column="contact_email" type="string" nullable="true" />
        <field name="contactPhoneNumber" column="contact_phone_number" type="string" nullable="true" />
        <field name="skippingShippingStepAllowed" column="skipping_shipping_step_allowed" type="boolean" />
        <field name="skippingPaymentStepAllowed" column="skipping_payment_step_allowed" type="boolean" />
        <field name="accountVerificationRequired" column="account_verification_required" type="boolean" />
        <field name="shippingAddressInCheckoutRequired" column="shipping_address_in_checkout_required" type="boolean">
            <options>
                <option name="default">0</option>
            </options>
        </field>

        <many-to-one field="defaultLocale" target-entity="Sylius\Component\Locale\Model\LocaleInterface" fetch="EAGER">
            <join-column name="default_locale_id" referenced-column-name="id" nullable="false" />
        </many-to-one>
        <many-to-one field="baseCurrency" target-entity="Sylius\Component\Currency\Model\CurrencyInterface" fetch="EAGER">
            <join-column name="base_currency_id" referenced-column-name="id" nullable="false" />
        </many-to-one>
        <many-to-one field="defaultTaxZone" target-entity="Sylius\Component\Addressing\Model\ZoneInterface">
            <join-column name="default_tax_zone_id" referenced-column-name="id" nullable="true" on-delete="SET NULL" />
        </many-to-one>
        <many-to-one field="menuTaxon" target-entity="Sylius\Component\Core\Model\TaxonInterface">
            <join-column name="menu_taxon_id" referenced-column-name="id" nullable="true" on-delete="SET NULL" />
        </many-to-one>
        <many-to-many field="currencies" target-entity="Sylius\Component\Currency\Model\CurrencyInterface">
            <order-by>
                <order-by-field name="id" />
            </order-by>

            <join-table name="sylius_channel_currencies">
                <join-columns>
                    <join-column name="channel_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
                </join-columns>
                <inverse-join-columns>
                    <join-column name="currency_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
                </inverse-join-columns>
            </join-table>
        </many-to-many>
        <many-to-many field="locales" target-entity="Sylius\Component\Locale\Model\LocaleInterface">
            <join-table name="sylius_channel_locales">
                <join-columns>
                    <join-column name="channel_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
                </join-columns>
                <inverse-join-columns>
                    <join-column name="locale_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
                </inverse-join-columns>
            </join-table>
        </many-to-many>
        <many-to-many field="countries" target-entity="Sylius\Component\Addressing\Model\CountryInterface">
            <join-table name="sylius_channel_countries">
                <join-columns>
                    <join-column name="channel_id" nullable="false" on-delete="CASCADE" />
                </join-columns>
                <inverse-join-columns>
                    <join-column name="country_id" nullable="false" on-delete="CASCADE" />
                </inverse-join-columns>
            </join-table>
        </many-to-many>

        <one-to-one field="shopBillingData" target-entity="Sylius\Component\Core\Model\ShopBillingDataInterface">
            <join-column name="shop_billing_data_id" on-delete="CASCADE"/>
            <cascade>
                <cascade-all />
            </cascade>
        </one-to-one>

        <one-to-one field="channelPriceHistoryConfig" target-entity="Sylius\Component\Core\Model\ChannelPriceHistoryConfigInterface">
            <join-column name="channel_price_history_config_id" on-delete="CASCADE"/>
            <cascade>
                <cascade-all />
            </cascade>
        </one-to-one>
    </mapped-superclass>
</doctrine-mapping>
