package cc.catalysts.boot.i18n.config;

import cc.catalysts.boot.i18n.controller.I18nController;
import cc.catalysts.boot.i18n.service.I18nService;
import cc.catalysts.boot.i18n.service.ListResourceBundleMessageSource;
import cc.catalysts.boot.i18n.service.impl.I18nServiceImpl;
import cc.catalysts.boot.i18n.service.impl.ListResourceBundleMessageSourceImpl;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

import java.nio.charset.Charset;

/**
 * @author Thomas Scheinecker
 */
@Configuration
@ConditionalOnMissingBean(value = MessageSource.class, search = SearchStrategy.CURRENT)
@Conditional(I18nAutoConfiguration.CatResourceBundleCondition.class)
@AutoConfigureBefore(MessageSourceAutoConfiguration.class)
@ConfigurationProperties(prefix = "spring.messages")
public class I18nAutoConfiguration extends MessageSourceAutoConfiguration {

    protected static class CatResourceBundleCondition extends ResourceBundleCondition {}

    private String[] getBasenames() {
        String basename = getBasename();
        if (StringUtils.hasText(basename)) {
            return StringUtils.commaDelimitedListToStringArray(StringUtils.trimAllWhitespace(basename));
        }

        return null;
    }

    @Bean
    @Override
    public ListResourceBundleMessageSourceImpl messageSource() {
        ListResourceBundleMessageSourceImpl messageSource = new ListResourceBundleMessageSourceImpl();

        String[] basenames = getBasenames();
        if (basenames != null) {
            messageSource.setBasenames(basenames);
        }

        Charset encoding = getEncoding();
        if (encoding != null) {
            messageSource.setDefaultEncoding(encoding.name());
        }
        messageSource.setFallbackToSystemLocale(isFallbackToSystemLocale());
        messageSource.setCacheSeconds(getCacheSeconds());

        return messageSource;
    }

    @Bean
    I18nService i18nApi(ListResourceBundleMessageSource messageSource) {
        return new I18nServiceImpl(messageSource);
    }

    @Bean
    I18nController i18nController(I18nService i18NService) {
        return new I18nController(i18NService);
    }
}

@@ -33,16 +33,79 @@
 onfig;%0A%0A
+import cc.catalysts.boot.i18n.controller.ClientEnumController;%0A
 import c
@@ -2767,11 +2767,161 @@
 );%0A    %7D
+%0A%0A    @Bean%0A    ClientEnumController clientEnumController(MessageSource messageSource) %7B%0A        return new ClientEnumController(messageSource);%0A    %7D
 %0A%7D%0A

add controller