package com.softwarebr.nunu.config.domain.impl;

import com.softwarebr.nunu.config.domain.AbstractConfigService;
import com.softwarebr.nunu.config.domain.ConfigService;
import com.softwarebr.nunu.domain.AgreementConfig;
import com.softwarebr.nunu.domain.PayConfig;
import com.softwarebr.nunu.domain.SMSConfig;
import com.softwarebr.nunu.domain.ServiceTerms;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

;

/**
 * 配置
 * 最大化适应需求变更
 * @author xu
 * @date 2019/10/28 17:49
 */
@Configuration
public class ConfigServiceImpl {

    private <T> AbstractConfigService<T> createConfigService(String key, Class<T> domainClass){
        return new AbstractConfigService<T>(){
            @Override
            public String getKey() {
                return key;
            }
            @Override
            public Class<T> getDomainClass() {
                return domainClass;
            }
        };
    }

    @Bean
    public ConfigService<SMSConfig> smsConfig(){
        return createConfigService(SMSConfig.KEY, SMSConfig.class);
    }

    @Bean
    public ConfigService<PayConfig> payConfig(){
        return createConfigService(PayConfig.KEY, PayConfig.class);
    }


    @Bean
    public ConfigService<ServiceTerms> serviceTerms(){
        return createConfigService(ServiceTerms.KEY, ServiceTerms.class);
    }

    @Bean
    public ConfigService<AgreementConfig> agreement(){
        return createConfigService(AgreementConfig.KEY, AgreementConfig.class);
    }

}
