package me.qwq.doghouse.config;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;

import me.qwq.doghouse.interfaces.IConfig;
import me.qwq.doghouse.service.ConfigService;

public class ConfigServiceFactoryBean<T extends IConfig<T>> implements FactoryBean<T> {

    private final Class<T> targetClass;
    
    @Autowired
    private ConfigService configService;

    public ConfigServiceFactoryBean(Class<T> targetClass) {
        this.targetClass = targetClass;
    }

    @Override
    public T getObject() throws Exception {
        return configService.getConfig(targetClass);
    }

    @Override
    public Class<?> getObjectType() {
        return targetClass;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
