<?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\Currency\Model\ExchangeRate" table="sylius_exchange_rate">
        <unique-constraints>
            <unique-constraint columns="source_currency,target_currency"/>
        </unique-constraints>

        <id name="id" column="id" type="integer">
            <generator strategy="AUTO" />
        </id>

        <field name="ratio" column="ratio" type="decimal" precision="10" scale="5" />

        <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 field="sourceCurrency" target-entity="Sylius\Component\Currency\Model\CurrencyInterface">
            <join-column name="source_currency" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
        </many-to-one>
        <many-to-one field="targetCurrency" target-entity="Sylius\Component\Currency\Model\CurrencyInterface">
            <join-column name="target_currency" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
        </many-to-one>
    </mapped-superclass>
</doctrine-mapping>
