# This file is a part of the Sylius package.
# (c) Sylius Sp. z o.o.

sylius_shop_account_address_book_index:
    path: /
    methods: [GET]
    defaults:
        _controller: sylius.controller.address::indexAction
        _sylius:
            section: shop_account
            template: "@SyliusShop/account/address_book/index.html.twig"
            paginate: false
            repository:
                method: findByCustomer
                arguments:
                    - "expr:service('sylius.context.customer').getCustomer()"

sylius_shop_account_address_book_create:
    path: /add
    methods: [GET, POST]
    defaults:
        _controller: sylius.controller.address::createAction
        _sylius:
            form:
                type: Sylius\Bundle\ShopBundle\Form\Type\AddressType
            section: shop_account
            template: "@SyliusShop/account/address_book/create.html.twig"
            factory:
                method: createForCustomer
                arguments:
                    - "expr:service('sylius.context.customer').getCustomer()"
            redirect:
                route: sylius_shop_account_address_book_index
                parameters: {}
            flash: sylius.customer.add_address

sylius_shop_account_address_book_update:
    path: /{id}/edit
    methods: [GET, PUT]
    defaults:
        _controller: sylius.controller.address::updateAction
        _sylius:
            form:
                type: Sylius\Bundle\ShopBundle\Form\Type\AddressType
            section: shop_account
            template: "@SyliusShop/account/address_book/update.html.twig"
            repository:
                method: findOneByCustomer
                arguments:
                    - $id
                    - "expr:service('sylius.context.customer').getCustomer()"
            redirect:
                route: sylius_shop_account_address_book_index
                parameters: {}

sylius_shop_account_address_book_delete:
    path: /{id}
    methods: [DELETE]
    defaults:
        _controller: sylius.controller.address::deleteAction
        _sylius:
            section: shop_account
            repository:
                method: findOneByCustomer
                arguments:
                    - $id
                    - "expr:service('sylius.context.customer').getCustomer()"
            redirect: sylius_shop_account_address_book_index

sylius_shop_account_address_book_set_as_default:
    path: /{id}/set-as-default
    methods: [GET, PATCH]
    defaults:
        _controller: sylius.controller.customer::updateAction
        _sylius:
            section: shop_account
            form:
                type: Sylius\Bundle\ShopBundle\Form\Type\CustomerDefaultAddressType
                options:
                    customer: "expr:service('sylius.context.customer').getCustomer()"
            repository:
                method: find
                arguments:
                    - "expr:service('sylius.context.customer').getCustomer()"
            redirect:
                route: sylius_shop_account_address_book_index
                parameters: {}
            flash: sylius.customer.set_address_as_default
