package me.qwq.doghouse.interfaces;

import org.springframework.stereotype.Component;

import me.qwq.doghouse.service.ConfigService;
import me.qwq.doghouse.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);
    }
    
    @SuppressWarnings("unchecked")
    public default T afterSaving() {
        return (T) this;
    }
    
    @SuppressWarnings("unchecked")
    public default T beforeSaving() {
        return (T) this;
    }
}
