<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

    <services>

        <!-- Entity Definition -->
        <service id="JGA\RevocationButton\Core\Content\Revocation\RevocationDefinition">
            <tag name="shopware.entity.definition" entity="jga_revocation"/>
        </service>

        <!-- Consent Services -->
        <service id="JGA\RevocationButton\Storefront\Consent\ConsentLinkResolver">
            <argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService"/>
            <argument type="service" id="router"/>
        </service>

        <service id="JGA\RevocationButton\Storefront\Consent\ConsentItemProvider">
            <argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService"/>
            <argument type="service" id="JGA\RevocationButton\Storefront\Consent\ConsentLinkResolver"/>
            <argument type="service" id="language.repository"/>
            <argument type="service" id="Shopware\Core\Framework\Util\HtmlSanitizer"/>
        </service>

        <!-- Excluded Line Item Detector -->
        <service id="JGA\RevocationButton\Core\Service\ExcludedLineItemDetector">
            <argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService"/>
            <argument type="service" id="Shopware\Core\Content\ProductStream\Service\ProductStreamBuilder"/>
            <argument type="service" id="product.repository"/>
        </service>

        <!-- Notification Recipient Parser (splits the comma-separated internal notification config into a recipient map) -->
        <service id="JGA\RevocationButton\Core\Service\NotificationRecipientParser"/>

        <!-- Customer Group Exclusion Evaluator (disables revocation for configured B2B customer groups) -->
        <service id="JGA\RevocationButton\Core\Service\CustomerGroupExclusionEvaluator">
            <argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService"/>
            <argument type="service" id="rule.repository"/>
            <argument type="service" id="order.repository"/>
            <argument type="service" id="Shopware\Core\Checkout\Cart\Order\OrderConverter"/>
        </service>

        <!-- Revocation Recorder (write path: persistence, idempotency, state transition, tagging) -->
        <service id="JGA\RevocationButton\Core\Service\RevocationRecorder">
            <argument type="service" id="jga_revocation.repository"/>
            <argument type="service" id="order.repository"/>
            <argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService"/>
            <argument type="service" id="event_dispatcher"/>
            <argument type="service" id="Shopware\Core\System\StateMachine\StateMachineRegistry"/>
        </service>

        <!-- Revocation Form Settings (optional form parts: reason field, captcha) -->
        <service id="JGA\RevocationButton\Core\Service\RevocationFormSettings">
            <argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService"/>
        </service>

        <!-- Revocation Period Evaluator (single source of truth for the deadline check) -->
        <service id="JGA\RevocationButton\Core\Service\RevocationPeriodEvaluator">
            <argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService"/>
            <argument type="service" id="state_machine_history.repository"/>
            <argument type="service" id="document.repository"/>
        </service>

        <!-- Storefront Controller -->
        <service id="JGA\RevocationButton\Storefront\Controller\RevocationController" public="true">
            <argument type="service" id="order.repository"/>
            <argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService"/>
            <argument type="service" id="JGA\RevocationButton\Core\Service\RevocationPeriodEvaluator"/>
            <argument type="service" id="Shopware\Storefront\Page\GenericPageLoader"/>
            <argument type="service" id="JGA\RevocationButton\Storefront\Consent\ConsentItemProvider"/>
            <argument type="service" id="JGA\RevocationButton\Core\Service\ExcludedLineItemDetector"/>
            <argument type="service" id="JGA\RevocationButton\Core\Service\RevocationRecorder"/>
            <argument type="service" id="JGA\RevocationButton\Core\Service\CustomerGroupExclusionEvaluator"/>
            <argument type="service" id="JGA\RevocationButton\Storefront\Consent\ConsentLinkResolver"/>
            <argument type="service" id="JGA\RevocationButton\Core\Service\RevocationFormSettings"/>
            <call method="setContainer">
                <argument type="service" id="service_container"/>
            </call>
        </service>

        <!-- Storefront Subscriber -->
        <service id="JGA\RevocationButton\Storefront\Subscriber\StorefrontSubscriber">
            <argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService"/>
            <argument type="service" id="JGA\RevocationButton\Core\Service\CustomerGroupExclusionEvaluator"/>
            <argument type="service" id="JGA\RevocationButton\Core\Service\RevocationPeriodEvaluator"/>
            <tag name="kernel.event_subscriber"/>
        </service>

        <!-- Captcha Exception Subscriber -->
        <service id="JGA\RevocationButton\Storefront\Subscriber\CaptchaExceptionSubscriber">
            <argument type="service" id="router"/>
            <argument type="service" id="translator"/>
            <tag name="kernel.event_subscriber"/>
        </service>

        <!-- Captcha Skip Subscriber (exempts the revocation form from the shop-wide captcha when configured) -->
        <service id="JGA\RevocationButton\Storefront\Subscriber\CaptchaSkipSubscriber">
            <argument type="service" id="JGA\RevocationButton\Core\Service\RevocationFormSettings"/>
            <tag name="kernel.event_subscriber"/>
        </service>

        <!-- Order Confirmation Mail Subscriber -->
        <service id="JGA\RevocationButton\Subscriber\OrderConfirmationMailSubscriber">
            <argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService"/>
            <argument type="service" id="mail_template.repository"/>
            <argument type="service" id="order.repository"/>
            <argument type="service" id="JGA\RevocationButton\Core\Service\CustomerGroupExclusionEvaluator"/>
            <tag name="kernel.event_subscriber"/>
        </service>

        <!-- Internal Notification Subscriber -->
        <service id="JGA\RevocationButton\Subscriber\InternalNotificationSubscriber">
            <argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService"/>
            <argument type="service" id="mail_template.repository"/>
            <argument type="service" id="Shopware\Core\Content\Mail\Service\MailService"/>
            <argument type="service" id="JGA\RevocationButton\Core\Service\NotificationRecipientParser"/>
            <tag name="kernel.event_subscriber"/>
        </service>

        <!-- CMS Element Resolver -->
        <service id="JGA\RevocationButton\Core\Content\Cms\RevocationButtonCmsElementResolver">
            <tag name="shopware.cms.data_resolver"/>
        </service>

    </services>

</container>
