package com.sv.service.api.config;

import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Spring配置
 *
 */
@Component
public class SpringProfiles {

    @Resource
    private Environment environment;

    /**
     * 判断是否为开发模式
     *
     * @return 是返回 {@code true}，反之 {@code false}
     */
    public boolean isDevelopment() {
        for (String profile : environment.getActiveProfiles()) {
            if (profile.contains("development")) {
                return true;
            }
        }
        return false;
    }

    /**
     * 判断是否为测试模式
     *
     * @return 是返回 {@code true}，反之 {@code false}
     */
    public boolean isTest() {
        for (String profile : environment.getActiveProfiles()) {
            if (profile.contains("test")) {
                return true;
            }
        }
        return false;
    }

    /**
     * 判断是否生产模式
     *
     * @return 是返回 {@code true}，反之 {@code false}
     */
    public boolean isProduction() {
        for (String profile : environment.getActiveProfiles()) {
            if (profile.contains("production")) {
                return true;
            }
        }
        return false;
    }
}
