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

        <collectionOperations>
            <collectionOperation name="admin_get">
                <attribute name="method">GET</attribute>
                <attribute name="path">/admin/customers</attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>admin:customer:index</attribute>
                        <attribute>sylius:admin:customer:index</attribute>
                    </attribute>
                </attribute>
                <attribute name="filters">
                    <attribute>sylius.api.customer_group_filter</attribute>
                </attribute>
            </collectionOperation>

            <collectionOperation name="admin_post">
                <attribute name="method">POST</attribute>
                <attribute name="path">/admin/customers</attribute>
                <attribute name="denormalization_context">
                    <attribute name="groups">
                        <attribute>admin:customer:create</attribute>
                        <attribute>sylius:admin:customer:create</attribute>
                    </attribute>
                </attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>admin:customer:show</attribute>
                        <attribute>sylius:admin:customer:show</attribute>
                    </attribute>
                </attribute>
                <attribute name="validation_groups">
                    <attribute>sylius</attribute>
                    <attribute>sylius_user_create</attribute>
                    <attribute>sylius_api_user_create</attribute>
                </attribute>
            </collectionOperation>

            <collectionOperation name="shop_post">
                <attribute name="method">POST</attribute>
                <attribute name="path">/shop/customers</attribute>
                <attribute name="openapi_context">
                    <attribute name="summary">Registers a new customer.</attribute>
                </attribute>
                <attribute name="denormalization_context">
                    <attribute name="groups">
                        <attribute>shop:customer:create</attribute>
                        <attribute>sylius:shop:customer:create</attribute>
                    </attribute>
                </attribute>
                <attribute name="messenger">input</attribute>
                <attribute name="input">Sylius\Bundle\ApiBundle\Command\Account\RegisterShopUser</attribute>
                <attribute name="output">false</attribute>
            </collectionOperation>
        </collectionOperations>

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

            <itemOperation name="admin_statistics_get">
                <attribute name="method">GET</attribute>
                <attribute name="path">/admin/customers/{id}/statistics</attribute>
                <attribute name="controller">Sylius\Bundle\ApiBundle\Controller\GetCustomerStatisticsAction</attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>admin:customer:statistics:show</attribute>
                        <attribute>sylius:admin:customer:statistics:show</attribute>
                    </attribute>
                </attribute>
            </itemOperation>

            <itemOperation name="admin_put">
                <attribute name="method">PUT</attribute>
                <attribute name="path">/admin/customers/{id}</attribute>
                <attribute name="denormalization_context">
                    <attribute name="groups">
                        <attribute>admin:customer:update</attribute>
                        <attribute>sylius:admin:customer:update</attribute>
                    </attribute>
                </attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>admin:customer:show</attribute>
                        <attribute>sylius:admin:customer:show</attribute>
                    </attribute>
                </attribute>
                <attribute name="validation_groups">
                    <attribute>sylius</attribute>
                    <attribute>sylius_api_user_update</attribute>
                </attribute>
            </itemOperation>

            <itemOperation name="admin_delete_user">
                <attribute name="method">DELETE</attribute>
                <attribute name="path">/admin/customers/{id}/user</attribute>
                <attribute name="controller">Sylius\Bundle\ApiBundle\Controller\RemoveCustomerShopUserAction</attribute>
            </itemOperation>

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

            <itemOperation name="shop_password_update">
                <attribute name="method">PUT</attribute>
                <attribute name="path">/shop/customers/{id}/password</attribute>
                <attribute name="messenger">input</attribute>
                <attribute name="input">Sylius\Bundle\ApiBundle\Command\Account\ChangeShopUserPassword</attribute>
                <attribute name="output">false</attribute>
                <attribute name="denormalization_context">
                    <attribute name="groups">
                        <attribute>shop:customer:password:update</attribute>
                        <attribute>sylius:shop:customer:password:update</attribute>
                    </attribute>
                </attribute>
                <attribute name="openapi_context">
                    <attribute name="summary">Change password for logged in customer.</attribute>
                </attribute>
            </itemOperation>

            <itemOperation name="shop_put">
                <attribute name="method">PUT</attribute>
                <attribute name="path">/shop/customers/{id}</attribute>
                <attribute name="denormalization_context">
                    <attribute name="groups">
                        <attribute>shop:customer:update</attribute>
                        <attribute>sylius:shop:customer:update</attribute>
                    </attribute>
                </attribute>
                <attribute name="normalization_context">
                    <attribute name="groups">
                        <attribute>shop:customer:show</attribute>
                        <attribute>sylius:shop:customer:show</attribute>
                    </attribute>
                </attribute>
                <attribute name="validation_groups">
                    <attribute>sylius</attribute>
                    <attribute>sylius_api_user_update</attribute>
                    <attribute>sylius_customer_profile</attribute>
                </attribute>
            </itemOperation>
        </itemOperations>

        <property name="id" identifier="true" writable="false" />
        <property name="email" writable="true" />
        <property name="firstName" writable="true" />
        <property name="lastName" writable="true" />
        <property name="fullName" writable="false" />
        <property name="defaultAddress" writable="true" />
        <property name="subscribedToNewsletter" writable="true" />
        <property name="user" readable="true" writable="true" />
    </resource>
</resources>
