package link.at17.mid.tushare.interfaces;

import org.springframework.stereotype.Component;

import jakarta.annotation.PostConstruct;
import link.at17.mid.tushare.service.ConfigService;
import link.at17.mid.tushare.system.util.SpringContextHolder;

/**
 * 配置项必须实现该接口
 * 
 * @author Doghole
 *
 */
@Component
public interface IConfig<T extends IConfig<T>> {

    @SuppressWarnings("unchecked")
    public default boolean saveOrUpdate() {
        return SpringContextHolder.getBean(ConfigService.class).saveOrUpdate((T)this);
    }

    /**
     * 保存前处理。无论 @ConfigInfo 是否设置 save = true 都会调用
     */
    @SuppressWarnings("unchecked")
    public default T afterSaving() {
        return (T) this;
    }

    /**
     * 保存后处理。无论 @ConfigInfo 是否设置 save = true 都会调用
     */
    @SuppressWarnings("unchecked")
    public default T beforeSaving() {
        return (T) this;
    }
    
    /**
     * 初始化完成之后的方法，会在
     * <code><i>beanFactory</i>.autowireBean(bean)</code>
     * 和
     * <code><i>beanFactory</i>.initializeBean(bean, beanName)</code>
     * 后执行。<br>
     * @see quant.rich.emoney.config.ConfigServiceFactoryBean
     */
    @PostConstruct
    public default void afterBeanInit() {}
    
    public static class Views {
        public static class Persistence {}
    }
    
}
