package com.jeesharp.business.modules.pay.paytype.pufapay.config;

import com.jeesharp.business.modules.pay.paypufaconfig.config.PayPufaConfigHolder;
import com.jeesharp.business.modules.pay.paypufaconfig.entity.PayPufaConfig;
import com.jeesharp.business.modules.pay.paypufaconfig.service.PayPufaConfigService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import jakarta.annotation.PostConstruct;

/**
 * 启动时若库表已有平台浦发配置则覆盖 YAML 占位静态字段。
 *
 * @author jeesharp
 * @since 2026-05-25
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class PuFaPayChannelBootstrap {

    private final PayPufaConfigService payPufaConfigService;
    private final PayPufaConfigHolder payPufaConfigHolder;

    @PostConstruct
    public void init() {
        PayPufaConfig db = payPufaConfigService.findActive(null);
        if (db != null) {
            payPufaConfigHolder.applyFromConfig(db);
            log.info("浦发渠道已加载库表平台默认配置，跳过仅依赖 pufa-pay.properties");
            return;
        }
        log.info("浦发渠道使用 classpath:pufa-pay.properties 占位配置");
    }
}
