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

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

        <collectionOperations>
            <collectionOperation name="admin_get">
                <attribute name="method">GET</attribute>
                <attribute name="path">/admin/shipments</attribute>
                <attribute name="filters">
                    <attribute>sylius.api.search_shipment_filter</attribute>
                </attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>admin:shipment:index</attribute>
                        <attribute>sylius:admin:shipment:index</attribute>
                    </attribute>
                </attribute>
            </collectionOperation>
        </collectionOperations>

        <itemOperations>
            <itemOperation name="admin_get">
                <attribute name="method">GET</attribute>
                <attribute name="path">/admin/shipments/{id}</attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>admin:shipment:show</attribute>
                        <attribute>sylius:admin:shipment:show</attribute>
                    </attribute>
                </attribute>
            </itemOperation>

            <itemOperation name="shop_get">
                <attribute name="method">GET</attribute>
                <attribute name="path">/shop/shipments/{id}</attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>shop:shipment:show</attribute>
                        <attribute>sylius:shop:shipment:show</attribute>
                    </attribute>
                </attribute>
            </itemOperation>

            <itemOperation name="admin_ship">
                <attribute name="method">PATCH</attribute>
                <attribute name="path">/admin/shipments/{id}/ship</attribute>
                <attribute name="messenger">input</attribute>
                <attribute name="input">Sylius\Bundle\ApiBundle\Command\Checkout\ShipShipment</attribute>
                <attribute name="output">false</attribute>
                <attribute name="status">202</attribute>
                <attribute name="openapi_context">
                    <attribute name="summary">Ships Shipment.</attribute>
                </attribute>
                <attribute name="denormalization_context">
                    <attribute name="groups">
                        <attribute>admin:shipment:update</attribute>
                        <attribute>sylius:admin:shipment:update</attribute>
                    </attribute>
                </attribute>
            </itemOperation>

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

        <subresourceOperations>
            <subresourceOperation name="api_orders_shipments_get_subresource">
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>admin:shipment:show</attribute>
                        <attribute>sylius:admin:shipment:show</attribute>
                    </attribute>
                </attribute>
            </subresourceOperation>

            <subresourceOperation name="adjustments_get_subresource">
                <attribute name="method">GET</attribute>
                <attribute name="path">/admin/shipments/{id}/adjustments</attribute>
            </subresourceOperation>
        </subresourceOperations>

        <property name="id" identifier="true" />
        <property name="createdAt" />
        <property name="updatedAt" />
        <property name="state" />
        <property name="units" />
        <property name="tracking" />
        <property name="shippedAt" />
        <property name="order" />
        <property name="adjustments" readable="true">
            <subresource resourceClass="%sylius.model.adjustment.class%" />
        </property>
    </resource>
</resources>
