package com.unicorn.hgzero.notification.config;

import com.azure.storage.blob.BlobContainerAsyncClient;
import com.azure.storage.blob.BlobContainerClientBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Azure Blob Storage 설정
 *
 * Event Hub Checkpoint 저장용 Blob Storage 연결 구성
 * EventProcessorClient의 체크포인트 저장소로 사용
 *
 * @author 준호 (Backend Developer)
 * @version 1.0
 * @since 2025-10-23
 */
@Slf4j
@Configuration
@ConditionalOnProperty(
    name = "azure.eventhub.enabled",
    havingValue = "true",
    matchIfMissing = false
)
public class BlobStorageConfig {

    @Value("${azure.storage.connection-string}")
    private String storageConnectionString;

    @Value("${azure.storage.container-name}")
    private String containerName;

    /**
     * Blob Container Async Client Bean 생성
     *
     * @return Blob Container Async Client
     */
    @Bean
    public BlobContainerAsyncClient blobContainerAsyncClient() {
        log.info("BlobContainerAsyncClient 생성 중 - Container: {}", containerName);

        BlobContainerAsyncClient client = new BlobContainerClientBuilder()
            .connectionString(storageConnectionString)
            .containerName(containerName)
            .buildAsyncClient();

        log.info("BlobContainerAsyncClient 생성 완료");

        return client;
    }
}
