package com.brilliance.mda.runtime.mda.driver.compile.component;

import com.brilliance.mda.runtime.mda.IModule;
import com.brilliance.mda.runtime.mda.IModuleList;
import com.brilliance.mda.runtime.mda.driver.MdaDriver;
import com.brilliance.mda.runtime.mda.driver.compile.processor.ModuleAnnotationProcess;
import lombok.AllArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@AllArgsConstructor
public class DefaultAutoCompileScopeEmitter extends AbstractAutoCompileScopeEmitter{

    private Class transClass;

    @Override
    public Class<?> relatedTransaction() {
        return transClass;
    }

    public IModule getRoot(){
        return this.getContext();
    }

    @Override
    public List<IModuleList> getAllModuleList() {
        String moduleName = getModuleName();
        ModuleRuleContext moduleRuleContext = ModuleAnnotationProcess.cache.get(moduleName);
        if(moduleRuleContext == null)
            return new ArrayList<>();
        return moduleRuleContext.getModuleList().stream().map(item->{
            return MdaDriver.getModuleList(this.getRoot(),item);
        }).collect(Collectors.toList());
    }
}
