/**
 * 
 */
package org.springblade.core.mp.processor;

import java.util.Properties;

import org.aopalliance.intercept.MethodInvocation;

import com.baomidou.dynamic.datasource.processor.DsProcessor;

import lombok.extern.slf4j.Slf4j;

/**
 * @author wookvn
 *
 */
@Slf4j
public class YmlDsProcessor extends DsProcessor {
	
	/**
     * yml prefix
     */
    private static final String YML_PREFIX = "#yml";
    
    private Properties ymlProperties = new Properties();
    
    public YmlDsProcessor(Properties ymlProperties) {
    	this.ymlProperties = ymlProperties;
    }
	
	@Override
	public boolean matches(String key) {
		return key.startsWith(YML_PREFIX);
	}

	@Override
	public String doDetermineDatasource(MethodInvocation invocation, String key) {
		String otherKeyStr = key.replace(YML_PREFIX + ".", "");
		String value = ymlProperties.getProperty(otherKeyStr);
		log.info("YmlDsProcessor|key:{},otherKey:{},value:{}", key, otherKeyStr, value);
		return value;
	}

}
