<?xml version="1.0" ?>

<!--

 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.

-->

<resources xmlns="https://api-platform.com/schema/metadata"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="https://api-platform.com/schema/metadata https://api-platform.com/schema/metadata/metadata-2.0.xsd"
>
    <resource class="%sylius.model.promotion.class%" shortName="Promotion">
        <attribute name="route_prefix">admin</attribute>

        <attribute name="validation_groups">
            <attribute>sylius</attribute>
            <attribute>sylius_api</attribute>
        </attribute>

        <attribute name="order">
            <attribute name="priority">DESC</attribute>
        </attribute>

        <collectionOperations>
            <collectionOperation name="admin_post">
                <attribute name="method">POST</attribute>
                <attribute name="denormalization_context">
                    <attribute name="groups">
                        <attribute>admin:promotion:create</attribute>
                        <attribute>sylius:admin:promotion:create</attribute>
                    </attribute>
                </attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>admin:promotion:show</attribute>
                        <attribute>sylius:admin:promotion:show</attribute>
                    </attribute>
                    <!-- It auto-turned on when adding PATCH itemOperations: https://github.com/api-platform/core/issues/3600 -->
                    <attribute name="skip_null_values">false</attribute>
                </attribute>
                <attribute name="openapi_context">
                    <attribute name="description">
Example configuration for `total_of_items_from_taxon` rule type:

```
{
    "type": "total_of_items_from_taxon",
    "configuration": {
        "channel-code": {
            "taxon": "taxon-code",
            "amount": int
        }
    }
}
```

Example configuration for `order_fixed_discount` action type:

```
{
    "type": "order_fixed_discount",
    "configuration": {
        "channel-code": {
            "amount": int,
        }
    }
}
```
                    </attribute>
                </attribute>
            </collectionOperation>

            <collectionOperation name="admin_get">
                <attribute name="method">GET</attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>admin:promotion:index</attribute>
                        <attribute>sylius:admin:promotion:index</attribute>
                    </attribute>
                    <!-- It auto-turned on when adding PATCH itemOperations: https://github.com/api-platform/core/issues/3600 -->
                    <attribute name="skip_null_values">false</attribute>
                </attribute>
                <attribute name="filters">
                    <attribute>sylius.api.promotion_coupon_search_filter</attribute>
                    <attribute>sylius.api.promotion_order_filter</attribute>
                    <attribute>sylius.api.exists_filter.archived_at</attribute>
                </attribute>
            </collectionOperation>
        </collectionOperations>

        <itemOperations>
            <itemOperation name="admin_get">
                <attribute name="method">GET</attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>admin:promotion:show</attribute>
                        <attribute>sylius:admin:promotion:show</attribute>
                    </attribute>
                    <!-- It auto-turned on when adding PATCH itemOperations: https://github.com/api-platform/core/issues/3600 -->
                    <attribute name="skip_null_values">false</attribute>
                </attribute>
            </itemOperation>

            <itemOperation name="admin_put">
                <attribute name="method">PUT</attribute>
                <attribute name="denormalization_context">
                    <attribute name="groups">
                        <attribute>admin:promotion:update</attribute>
                        <attribute>sylius:admin:promotion:update</attribute>
                    </attribute>
                </attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>admin:promotion:show</attribute>
                        <attribute>sylius:admin:promotion:show</attribute>
                    </attribute>
                    <!-- It auto-turned on when adding PATCH itemOperations: https://github.com/api-platform/core/issues/3600 -->
                    <attribute name="skip_null_values">false</attribute>
                </attribute>
                <attribute name="openapi_context">
                    <attribute name="description">
Example configuration for `total_of_items_from_taxon` rule type:

```
{
    "type": "total_of_items_from_taxon",
    "configuration": {
        "channel-code": {
            "taxon": "taxon-code",
            "amount": int
        }
    }
}
```

Example configuration for `order_fixed_discount` action type:

```
{
    "type": "order_fixed_discount",
    "configuration": {
        "channel-code": {
            "amount": int,
        }
    }
}
```
                    </attribute>
                </attribute>
            </itemOperation>

            <itemOperation name="admin_archive">
                <attribute name="method">PATCH</attribute>
                <attribute name="path">/promotions/{code}/archive</attribute>
                <attribute name="input">false</attribute>
                <attribute name="controller">Sylius\Bundle\ApiBundle\Applicator\ArchivingPromotionApplicatorInterface::archive</attribute>
                <attribute name="openapi_context">
                    <attribute name="summary">Archives Promotion.</attribute>
                </attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>admin:promotion:read</attribute>
                        <attribute>sylius:admin:promotion:read</attribute>
                    </attribute>
                </attribute>
            </itemOperation>
            <itemOperation name="admin_restore">
                <attribute name="method">PATCH</attribute>
                <attribute name="path">/promotions/{code}/restore</attribute>
                <attribute name="input">false</attribute>
                <attribute name="controller">Sylius\Bundle\ApiBundle\Applicator\ArchivingPromotionApplicatorInterface::restore</attribute>
                <attribute name="openapi_context">
                    <attribute name="summary">Restores Archived Promotion.</attribute>
                </attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>admin:promotion:read</attribute>
                        <attribute>sylius:admin:promotion:read</attribute>
                    </attribute>
                </attribute>
            </itemOperation>

            <itemOperation name="admin_delete">
                <attribute name="method">DELETE</attribute>
            </itemOperation>
        </itemOperations>

        <subresourceOperations>
            <subresourceOperation name="coupons_get_subresource">
                <attribute name="method">GET</attribute>
                <attribute name="path">/admin/promotions/{code}/coupons</attribute>
            </subresourceOperation>
        </subresourceOperations>

        <property name="id" identifier="false" writable="false" />
        <property name="code" identifier="true" readable="true" />
        <property name="name" readable="true" />
        <property name="description" readable="true" />
        <property name="priority" readable="true" />
        <property name="exclusive" readable="true" />
        <property name="appliesToDiscounted" readable="true" />
        <property name="usageLimit" readable="true" />
        <property name="startsAt" readable="true" />
        <property name="endsAt" readable="true" />
        <property name="couponBased" readable="true" />
        <property name="coupons" readable="true" writable="true">
            <subresource resourceClass="%sylius.model.promotion_coupon.class%" collection="true" />
        </property>
        <property name="rules" readable="true" />
        <property name="actions" readable="true" />
        <property name="channels" readable="true" />
        <property name="translations" readable="true" writable="true">
            <attribute name="openapi_context">
                <attribute name="type">object</attribute>
                <attribute name="example">
                    <attribute name="en_US">
                        <attribute name="label">string</attribute>
                    </attribute>
                </attribute>
            </attribute>
        </property>
    </resource>
</resources>
