<?php

declare(strict_types=1);

namespace App\Framework\Notification\Channels\WhatsApp;

use App\Framework\Attributes\Initializer;
use App\Framework\DI\Container;
use App\Framework\HttpClient\HttpClient;
use App\Framework\Notification\Channels\WhatsAppChannel;

/**
 * WhatsApp Notification Channel Initializer
 *
 * Registers WhatsApp notification components in the DI container
 */
final readonly class WhatsAppNotificationInitializer
{
    public function __construct(
        private Container $container
    ) {
    }

    #[Initializer]
    public function initialize(): void
    {
        // Register WhatsApp Config
        $this->container->singleton(
            WhatsAppConfig::class,
            fn () => WhatsAppConfig::createDefault()
        );

        // Register Phone Number Resolver
        $this->container->singleton(
            UserPhoneNumberResolver::class,
            fn () => FixedPhoneNumberResolver::createDefault()
        );

        // Register WhatsApp Client
        $this->container->singleton(
            WhatsAppClient::class,
            fn (Container $c) => new WhatsAppClient(
                httpClient: $c->get(HttpClient::class),
                config: $c->get(WhatsAppConfig::class)
            )
        );

        // Register WhatsApp Channel
        $this->container->singleton(
            WhatsAppChannel::class,
            fn (Container $c) => new WhatsAppChannel(
                client: $c->get(WhatsAppClient::class),
                phoneNumberResolver: $c->get(UserPhoneNumberResolver::class)
            )
        );
    }
}
