# 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/AddressBook/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:
            section: shop_account
            template: "@SyliusShop/Account/AddressBook/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:
            section: shop_account
            template: "@SyliusShop/Account/AddressBook/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
            template: "@SyliusShop/Account/AddressBook/_defaultAddressForm.html.twig"
            form:
                type: Sylius\Bundle\CoreBundle\Form\Type\Customer\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
