<?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.order.class%" shortName="Order">
        <attribute name="validation_groups">sylius</attribute>

        <collectionOperations>
            <collectionOperation name="admin_get">
                <attribute name="method">GET</attribute>
                <attribute name="path">/admin/orders</attribute>
                <attribute name="filters">
                    <attribute>sylius.api.order_channel_filter</attribute>
                    <attribute>sylius.api.order_currency_filter</attribute>
                    <attribute>sylius.api.order_customer_filter</attribute>
                    <attribute>sylius.api.order_date_filter</attribute>
                    <attribute>sylius.api.order_number_filter</attribute>
                    <attribute>sylius.api.order_product_filter</attribute>
                    <attribute>sylius.api.order_shipping_method_filter</attribute>
                    <attribute>sylius.api.order_total_filter</attribute>
                    <attribute>sylius.api.order_variants_filter</attribute>
                </attribute>
                <attribute name="order">
                    <attribute name="number">DESC</attribute>
                </attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>admin:order:index</attribute>
                        <attribute>sylius:admin:order:index</attribute>
                    </attribute>
                </attribute>
            </collectionOperation>

            <collectionOperation name="shop_post">
                <attribute name="method">POST</attribute>
                <attribute name="path">/shop/orders</attribute>
                <attribute name="messenger">input</attribute>
                <attribute name="input">Sylius\Bundle\ApiBundle\Command\Cart\PickupCart</attribute>
                <attribute name="denormalization_context">
                    <attribute name="groups">
                        <attribute>shop:order:create</attribute>
                        <attribute>sylius:shop:order:create</attribute>
                    </attribute>
                </attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>shop:order:show</attribute>
                        <attribute>sylius:shop:order:show</attribute>
                        <attribute>shop:cart:show</attribute>
                        <attribute>sylius:shop:cart:show</attribute>
                    </attribute>
                </attribute>
                <attribute name="openapi_context">
                    <attribute name="summary">Pickups a new cart.</attribute>
                </attribute>
            </collectionOperation>

            <collectionOperation name="shop_get">
                <attribute name="method">GET</attribute>
                <attribute name="path">/shop/orders</attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>shop:order:index</attribute>
                        <attribute>sylius:shop:order:index</attribute>
                    </attribute>
                </attribute>
            </collectionOperation>
        </collectionOperations>

        <itemOperations>
            <itemOperation name="admin_get">
                <attribute name="method">GET</attribute>
                <attribute name="path">/admin/orders/{tokenValue}</attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>admin:order:show</attribute>
                        <attribute>sylius:admin:order:show</attribute>
                    </attribute>
                </attribute>
            </itemOperation>

            <itemOperation name="admin_adjustments">
                <attribute name="method">GET</attribute>
                <attribute name="path">/admin/orders/{tokenValue}/adjustments</attribute>
                <attribute name="controller">Sylius\Bundle\ApiBundle\Controller\GetOrderAdjustmentsAction</attribute>
                <attribute name="write">false</attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>admin:adjustment:show</attribute>
                        <attribute>sylius:admin:adjustment:show</attribute>
                    </attribute>
                </attribute>
            </itemOperation>

            <itemOperation name="shop_get">
                <attribute name="method">GET</attribute>
                <attribute name="path">/shop/orders/{tokenValue}</attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>shop:cart:show</attribute>
                        <attribute>sylius:shop:cart:show</attribute>
                    </attribute>
                </attribute>
            </itemOperation>

            <itemOperation name="shop_delete">
                <attribute name="method">DELETE</attribute>
                <attribute name="path">/shop/orders/{tokenValue}</attribute>
                <attribute name="openapi_context">
                    <attribute name="summary">Deletes cart.</attribute>
                </attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>shop:order:show</attribute>
                        <attribute>sylius:shop:order:show</attribute>
                    </attribute>
                </attribute>
            </itemOperation>

            <itemOperation name="admin_cancel">
                <attribute name="method">PATCH</attribute>
                <attribute name="path">/admin/orders/{tokenValue}/cancel</attribute>
                <attribute name="input">false</attribute>
                <attribute name="controller">Sylius\Bundle\ApiBundle\Applicator\OrderStateMachineTransitionApplicatorInterface::cancel</attribute>
                <attribute name="denormalization_context">
                    <attribute name="groups">
                        <attribute>admin:order:update</attribute>
                        <attribute>sylius:admin:order:update</attribute>
                    </attribute>
                </attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>admin:order:show</attribute>
                        <attribute>sylius:admin:order:show</attribute>
                    </attribute>
                </attribute>
                <attribute name="openapi_context">
                    <attribute name="summary">Cancels Order.</attribute>
                </attribute>
            </itemOperation>

            <itemOperation name="shop_add_item">
                <attribute name="method">POST</attribute>
                <attribute name="path">/shop/orders/{tokenValue}/items</attribute>
                <attribute name="messenger">input</attribute>
                <attribute name="input">Sylius\Bundle\ApiBundle\Command\Cart\AddItemToCart</attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>shop:cart:show</attribute>
                        <attribute>sylius:shop:cart:show</attribute>
                    </attribute>
                </attribute>
                <attribute name="denormalization_context">
                    <attribute name="groups">
                        <attribute>shop:cart:add_item</attribute>
                        <attribute>sylius:shop:cart:add_item</attribute>
                    </attribute>
                </attribute>
                <attribute name="openapi_context">
                    <attribute name="summary">Adds Item to cart.</attribute>
                </attribute>
            </itemOperation>

            <itemOperation name="shop_select_shipping_method">
                <attribute name="method">PATCH</attribute>
                <attribute name="validation_groups">
                    <attribute>sylius</attribute>
                </attribute>
                <attribute name="path">/shop/orders/{tokenValue}/shipments/{shipmentId}</attribute>
                <attribute name="messenger">input</attribute>
                <attribute name="input">Sylius\Bundle\ApiBundle\Command\Checkout\ChooseShippingMethod</attribute>
                <attribute name="denormalization_context">
                    <attribute name="groups">
                        <attribute>shop:cart:select_shipping_method</attribute>
                        <attribute>sylius:shop:cart:select_shipping_method</attribute>
                    </attribute>
                </attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>shop:order:show</attribute>
                        <attribute>sylius:shop:order:show</attribute>
                        <attribute>shop:cart:show</attribute>
                        <attribute>sylius:shop:cart:show</attribute>
                    </attribute>
                </attribute>
                <attribute name="openapi_context">
                    <attribute name="summary">Selects shipping methods for particular shipment.</attribute>
                    <attribute name="parameters">
                        <attribute>
                            <attribute name="name">tokenValue</attribute>
                            <attribute name="in">path</attribute>
                            <attribute name="required">true</attribute>
                            <attribute name="schema">
                                <attribute name="type">string</attribute>
                            </attribute>
                        </attribute>
                        <attribute>
                            <attribute name="name">shipmentId</attribute>
                            <attribute name="in">path</attribute>
                            <attribute name="required">true</attribute>
                            <attribute name="schema">
                                <attribute name="type">string</attribute>
                            </attribute>
                        </attribute>
                    </attribute>
                </attribute>
            </itemOperation>

            <itemOperation name="shop_select_payment_method">
                <attribute name="method">PATCH</attribute>
                <attribute name="path">/shop/orders/{tokenValue}/payments/{paymentId}</attribute>
                <attribute name="messenger">input</attribute>
                <attribute name="input">Sylius\Bundle\ApiBundle\Command\Checkout\ChoosePaymentMethod</attribute>
                <attribute name="denormalization_context">
                    <attribute name="groups">
                        <attribute>shop:cart:select_payment_method</attribute>
                        <attribute>sylius:shop:cart:select_payment_method</attribute>
                    </attribute>
                </attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>shop:order:show</attribute>
                        <attribute>sylius:shop:order:show</attribute>
                        <attribute>shop:cart:show</attribute>
                        <attribute>sylius:shop:cart:show</attribute>
                    </attribute>
                </attribute>
                <attribute name="openapi_context">
                    <attribute name="summary">Selects payment methods for particular payment.</attribute>
                    <attribute name="parameters">
                        <attribute>
                            <attribute name="name">tokenValue</attribute>
                            <attribute name="in">path</attribute>
                            <attribute name="required">true</attribute>
                            <attribute name="schema">
                                <attribute name="type">string</attribute>
                            </attribute>
                        </attribute>
                        <attribute>
                            <attribute name="name">paymentId</attribute>
                            <attribute name="in">path</attribute>
                            <attribute name="required">true</attribute>
                            <attribute name="schema">
                                <attribute name="type">string</attribute>
                            </attribute>
                        </attribute>
                    </attribute>
                </attribute>
            </itemOperation>

            <itemOperation name="shop_account_change_payment_method">
                <attribute name="method">PATCH</attribute>
                <attribute name="path">/shop/account/orders/{tokenValue}/payments/{paymentId}</attribute>
                <attribute name="messenger">input</attribute>
                <attribute name="input">Sylius\Bundle\ApiBundle\Command\Account\ChangePaymentMethod</attribute>
                <attribute name="denormalization_context">
                    <attribute name="groups">
                        <attribute>shop:order:account:change_payment_method</attribute>
                        <attribute>sylius:shop:order:account:change_payment_method</attribute>
                    </attribute>
                </attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>shop:order:account:show</attribute>
                        <attribute>sylius:shop:order:account:show</attribute>
                    </attribute>
                </attribute>
                <attribute name="openapi_context">
                    <attribute name="summary">Change the payment method as logged shop user.</attribute>
                    <attribute name="parameters">
                        <attribute>
                            <attribute name="name">tokenValue</attribute>
                            <attribute name="in">path</attribute>
                            <attribute name="required">true</attribute>
                            <attribute name="schema">
                                <attribute name="type">string</attribute>
                            </attribute>
                        </attribute>
                        <attribute>
                            <attribute name="name">paymentId</attribute>
                            <attribute name="in">path</attribute>
                            <attribute name="required">true</attribute>
                            <attribute name="schema">
                                <attribute name="type">string</attribute>
                            </attribute>
                        </attribute>
                    </attribute>
                </attribute>
            </itemOperation>

            <itemOperation name="get_configuration">
                <attribute name="method">GET</attribute>
                <attribute name="controller">Sylius\Bundle\ApiBundle\Controller\Payment\GetPaymentConfiguration</attribute>
                <attribute name="path">/shop/orders/{tokenValue}/payments/{paymentId}/configuration</attribute>
                <attribute name="openapi_context">
                    <attribute name="summary">Retrieve payment method configuration.</attribute>
                    <attribute name="parameters">
                        <attribute>
                            <attribute name="name">tokenValue</attribute>
                            <attribute name="in">path</attribute>
                            <attribute name="required">true</attribute>
                            <attribute name="schema">
                                <attribute name="type">string</attribute>
                            </attribute>
                        </attribute>
                        <attribute>
                            <attribute name="name">paymentId</attribute>
                            <attribute name="in">path</attribute>
                            <attribute name="required">true</attribute>
                            <attribute name="schema">
                                <attribute name="type">string</attribute>
                            </attribute>
                        </attribute>
                    </attribute>
                </attribute>
            </itemOperation>

            <itemOperation name="shop_complete">
                <attribute name="method">PATCH</attribute>
                <attribute name="path">/shop/orders/{tokenValue}/complete</attribute>
                <attribute name="validation_groups">
                    <attribute>sylius</attribute>
                    <attribute>sylius_checkout_complete</attribute>
                </attribute>
                <attribute name="messenger">input</attribute>
                <attribute name="input">Sylius\Bundle\ApiBundle\Command\Checkout\CompleteOrder</attribute>
                <attribute name="denormalization_context">
                    <attribute name="groups">
                        <attribute>shop:cart:complete</attribute>
                        <attribute>sylius:shop:cart:complete</attribute>
                    </attribute>
                </attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>shop:order:show</attribute>
                        <attribute>sylius:shop:order:show</attribute>
                        <attribute>shop:cart:show</attribute>
                        <attribute>sylius:shop:cart:show</attribute>
                    </attribute>
                </attribute>
                <attribute name="openapi_context">
                    <attribute name="summary">Completes checkout.</attribute>
                </attribute>
            </itemOperation>

            <itemOperation name="shop_remove_item">
                <attribute name="method">DELETE</attribute>
                <attribute name="path">/shop/orders/{tokenValue}/items/{itemId}</attribute>
                <attribute name="controller">Sylius\Bundle\ApiBundle\Controller\DeleteOrderItemAction</attribute>
                <attribute name="write">false</attribute>
                <attribute name="denormalization_context">
                    <attribute name="groups">
                        <attribute>shop:cart:remove_item</attribute>
                        <attribute>sylius:shop:cart:remove_item</attribute>
                    </attribute>
                </attribute>
                <attribute name="openapi_context">
                    <attribute name="parameters">
                        <attribute>
                            <attribute name="name">tokenValue</attribute>
                            <attribute name="in">path</attribute>
                            <attribute name="required">true</attribute>
                            <attribute name="schema">
                                <attribute name="type">string</attribute>
                            </attribute>
                        </attribute>
                        <attribute>
                            <attribute name="name">itemId</attribute>
                            <attribute name="in">path</attribute>
                            <attribute name="required">true</attribute>
                            <attribute name="schema">
                                <attribute name="type">string</attribute>
                            </attribute>
                        </attribute>
                    </attribute>
                </attribute>
            </itemOperation>

            <itemOperation name="shop_change_quantity">
                <attribute name="method">PATCH</attribute>
                <attribute name="path">/shop/orders/{tokenValue}/items/{orderItemId}</attribute>
                <attribute name="messenger">input</attribute>
                <attribute name="input">Sylius\Bundle\ApiBundle\Command\Cart\ChangeItemQuantityInCart</attribute>
                <attribute name="denormalization_context">
                    <attribute name="groups">
                        <attribute>shop:cart:change_quantity</attribute>
                        <attribute>sylius:shop:cart:change_quantity</attribute>
                    </attribute>
                </attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>shop:cart:show</attribute>
                        <attribute>sylius:shop:cart:show</attribute>
                    </attribute>
                </attribute>
                <attribute name="openapi_context">
                    <attribute name="summary">Changes quantity of order item.</attribute>
                    <attribute name="parameters">
                        <attribute>
                            <attribute name="name">tokenValue</attribute>
                            <attribute name="in">path</attribute>
                            <attribute name="required">true</attribute>
                            <attribute name="schema">
                                <attribute name="type">string</attribute>
                            </attribute>
                        </attribute>
                        <attribute>
                            <attribute name="name">orderItemId</attribute>
                            <attribute name="in">path</attribute>
                            <attribute name="required">true</attribute>
                            <attribute name="schema">
                                <attribute name="type">string</attribute>
                            </attribute>
                        </attribute>
                    </attribute>
                </attribute>
            </itemOperation>

            <itemOperation name="shop_put">
                <attribute name="method">PUT</attribute>
                <attribute name="path">/shop/orders/{tokenValue}</attribute>
                <attribute name="messenger">input</attribute>
                <attribute name="input">Sylius\Bundle\ApiBundle\Command\Checkout\UpdateCart</attribute>
                <attribute name="denormalization_context">
                    <attribute name="groups">
                        <attribute>shop:cart:update</attribute>
                        <attribute>sylius:shop:cart:update</attribute>
                    </attribute>
                </attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>shop:order:show</attribute>
                        <attribute>sylius:shop:order:show</attribute>
                        <attribute>shop:cart:show</attribute>
                        <attribute>sylius:shop:cart:show</attribute>
                    </attribute>
                </attribute>
                <attribute name="openapi_context">
                    <attribute name="summary">Addresses cart to given location, logged in Customer does not have to provide an email. Applies coupon to cart.</attribute>
                </attribute>
            </itemOperation>

            <itemOperation name="admin_resend_confirmation">
                <attribute name="method">POST</attribute>
                <attribute name="path">/admin/orders/{tokenValue}/resend-confirmation-email</attribute>
                <attribute name="messenger">input</attribute>
                <attribute name="input">Sylius\Bundle\ApiBundle\Command\ResendOrderConfirmationEmail</attribute>
                <attribute name="output">false</attribute>
                <attribute name="status">202</attribute>
                <attribute name="openapi_context">
                    <attribute name="summary">Resends order confirmation email.</attribute>
                </attribute>
            </itemOperation>
        </itemOperations>

        <subresourceOperations>
            <subresourceOperation name="items_get_subresource">
                <attribute name="method">GET</attribute>
                <attribute name="path">/shop/orders/{tokenValue}/items</attribute>
            </subresourceOperation>

            <subresourceOperation name="shipments_get_subresource">
                <attribute name="method">GET</attribute>
                <attribute name="path">/admin/orders/{tokenValue}/shipments</attribute>
            </subresourceOperation>

            <subresourceOperation name="payments_get_subresource">
                <attribute name="method">GET</attribute>
                <attribute name="path">/admin/orders/{tokenValue}/payments</attribute>
            </subresourceOperation>

            <subresourceOperation name="adjustments_get_subresource">
                <attribute name="method">GET</attribute>
                <attribute name="path">/shop/orders/{tokenValue}/adjustments</attribute>
            </subresourceOperation>

            <subresourceOperation name="items_adjustments_get_subresource">
                <attribute name="method">GET</attribute>
                <attribute name="path">/shop/orders/{tokenValue}/items/{items}/adjustments</attribute>
            </subresourceOperation>
        </subresourceOperations>

        <property name="id" identifier="false" writable="false" />
        <property name="number" identifier="false" writable="false" />
        <property name="tokenValue" identifier="true" writable="false" />
        <property name="channel" writable="false" />
        <property name="customer" writable="false" />
        <property name="shipments" writable="false">
            <subresource resourceClass="%sylius.model.shipment.class%" />
        </property>
        <property name="payments" writable="false">
            <subresource resourceClass="%sylius.model.payment.class%" />
        </property>
        <property name="state" writable="false" />
        <property name="paymentState" writable="false" />
        <property name="shippingState" writable="false" />
        <property name="total" writable="false" />
        <property name="orderPromotionTotal" writable="false" />
        <property name="shippingPromotionTotal" writable="false" />
        <property name="items" readable="true" writable="true">
            <subresource resourceClass="%sylius.model.order_item.class%" />
        </property>
        <property name="notes" writable="true" />
        <property name="itemsTotal" readable="true" />
        <property name="taxTotal" readable="true"/>
        <property name="shippingTaxTotal" readable="true"/>
        <property name="taxExcludedTotal" readable="true"/>
        <property name="taxIncludedTotal" readable="true"/>
        <property name="adjustments" writable="false">
            <subresource resourceClass="%sylius.model.adjustment.class%" />
        </property>
        <property name="billingAddress" writable="false" />
        <property name="shippingAddress" writable="false" />
        <property name="localeCode" writable="true" />
    </resource>
</resources>
