package me.chyxion.tigon.codegen.service.support;

import java.util.Map;
import me.chyxion.tigon.codegen.model.CodeGenArgs;
import me.chyxion.tigon.codegen.service.CodeGenerator;

/**
 * @version 0.0.1
 * @since 0.0.1
 * @author Shaun Chyxion <br>
 * chyxion@163.com <br>
 * Oct 6, 2014 1:17:30 PM
 */
public class ServiceCodeGen extends CodeGenerator {

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean accept(Map<String, Object> dataModel) {
        return (Boolean) dataModel.get("genService");
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String process(Map<String, Object> dataModel, String module, String model) {
        String pkgDir = (String) dataModel.get("pkgDir");
        // interface
        String strRtn = render(new CodeGenArgs(
                CodeGenArgs.TARGET_SERVICE, 
                "/codegen/service.ftl", 
                dataModel, 
                codeDir + pkgDir + 
                    "/service/" + model + "Service.java"));
                
        // shiro
        strRtn +=";";
        strRtn += render(new CodeGenArgs(
                CodeGenArgs.TARGET_SERVICE_SUPPORT, 
                "/codegen/service-support.ftl", 
                dataModel,
                codeDir + pkgDir + 
                    "/service/shiro/" + model + "ServiceSupport.java"
                ));
        return strRtn;
    }
}
