${database.allClassCopyright}package ${glPackagePluginBuri};

import java.util.Map;
import java.util.HashMap;

import org.seasar.dbflute.Entity;

/**
 * The definition of Buri.
 * @author ${database.classAuthor}
 */
public class ${glBuriDef} {

    public static enum BuriProcess {
#set ($count = 0)
#foreach ($packageName in $database.getBuriPackageList())
#set ($processList = $database.getBuriProcessList($packageName))
#foreach ($processName in $processList)
#if ($count != 0)
        ,
#end
        ${packageName}_${processName}("${packageName}.${processName}")
#set ($count = $count + 1)
#end
#end
        ;
        private String _path;
        private BuriProcess(String path) {
            _path = path;
        }
        public String path() {
            return _path;
        }
        @Override
        public String toString() {
            return path();
        }
    }

    public static interface BuriStatus {
        String code();
        String path();
        BuriProcess process();
    }

    public static interface BuriAction {
        String code();
        BuriProcess process();
    }
#foreach ($packageName in $database.getBuriPackageList())
#set ($count = 0)
#set ($processList = $database.getBuriProcessList($packageName))
#foreach ($processName in $processList)
#set ($statusList = $database.getBuriStatusList($packageName, $processName))

    public enum ${packageName}_${processName}_Status implements BuriStatus {
#set ($count = 0)
#foreach ($statusName in $statusList)
#if ($count != 0)
        ,
#end
        $database.initCap(${statusName})("${statusName}")
#set ($count = $count + 1)
#end
        ;
        private static final Map<String, ${packageName}_${processName}_Status> _codeValueMap = new HashMap<String, ${packageName}_${processName}_Status>();
        static { for (${packageName}_${processName}_Status value : values()) { _codeValueMap.put(value.code().toLowerCase(), value); } }
        private String _code;
        private ${packageName}_${processName}_Status(String code) {
            _code = code;
        }
        public String code() {
            return _code;
        }
        public String path() {
            return process().path() + "." + _code;
        }
        public BuriProcess process() {
            return BuriProcess.${packageName}_${processName};
        }
        public static ${packageName}_${processName}_Status codeOf(Object code) {
            if (code == null) { return null; }
            final String codeStr = code.toString();
            if (codeStr.contains(".")) {
                final int beginIndex = codeStr.lastIndexOf(".") + ".".length();
                return _codeValueMap.get(codeStr.substring(beginIndex));
            } else {
                return _codeValueMap.get(codeStr);
            }
        }
        @Override
        public String toString() {
            return path();
        }
    }
#end
#foreach ($processName in $processList)
#set ($actionList = $database.getBuriActionList($packageName, $processName))

    public enum ${packageName}_${processName}_Action implements BuriAction {
#set ($count = 0)
#foreach ($actionName in $actionList)
#if ($count != 0)
        ,
#end
        $database.initCap(${actionName})("${actionName}")
#set ($count = $count + 1)
#end
        ;
        private static final Map<String, ${packageName}_${processName}_Action> _codeValueMap = new HashMap<String, ${packageName}_${processName}_Action>();
        static { for (${packageName}_${processName}_Action value : values()) { _codeValueMap.put(value.code().toLowerCase(), value); } }
        private String _code;
        private ${packageName}_${processName}_Action(String code) {
            _code = code;
        }
        public String code() {
            return _code;
        }
        public BuriProcess process() {
            return BuriProcess.${packageName}_${processName};
        }
        public static ${packageName}_${processName}_Action codeOf(Object code) {
            if (code == null) { return null; }
            final String codeStr = code.toString();
            if (codeStr.contains(".")) {
                final int beginIndex = codeStr.lastIndexOf(".") + ".".length();
                return _codeValueMap.get(codeStr.substring(beginIndex));
            } else {
                return _codeValueMap.get(codeStr);
            }
        }
        @Override
        public String toString() {
            return process().path() + ":" + code();
        }
    }
#end
#end

    public static interface BuriUserDataProvider {
        Object provide(BuriProcess process, Entity entity, BuriAction action);
    }
}
