package cn.stylefeng.team.generator.sdk.template.factory;

import cn.stylefeng.team.generator.api.enums.GeneratorTypeEnum;
import cn.stylefeng.team.generator.api.pojo.template.BizGeneratorTemplateGroup;
import cn.stylefeng.team.generator.api.pojo.template.GeneratorTemplate;

import java.util.ArrayList;
import java.util.List;

import static cn.stylefeng.team.generator.sdk.template.factory.TemplateFactory.getResourceContent;

public class BizTemplateFactory {

    public static BizGeneratorTemplateGroup createBizGenerateTemplateGroup() {

        BizGeneratorTemplateGroup bizGeneratorTemplateGroup = new BizGeneratorTemplateGroup();

        bizGeneratorTemplateGroup.setGeneratorTypeEnum(GeneratorTypeEnum.BIZ_BACKEND_GENERATE);

        List<GeneratorTemplate> mainTable = new ArrayList<>();

        mainTable.add(new GeneratorTemplate("/entity", ".java", getResourceContent("templates/guns-v8-biz/backend/common/entity.java.btl")));
        mainTable.add(new GeneratorTemplate("/enums", "ExceptionEnum.java", getResourceContent("templates/guns-v8-biz/backend/common/enum.java.btl")));

        mainTable.add(new GeneratorTemplate("/controller", "Controller.java", getResourceContent("templates/guns-v8-biz/backend/main-table/controller.java.btl")));
        mainTable.add(new GeneratorTemplate("/mapper", "Mapper.java", getResourceContent("templates/guns-v8-biz/backend/main-table/mapper.java.btl")));
        mainTable.add(new GeneratorTemplate("/mapper/mapping", "Mapper.xml", getResourceContent("templates/guns-v8-biz/backend/main-table/mapping.xml.btl")));
        mainTable.add(new GeneratorTemplate("/pojo/request", "Request.java", getResourceContent("templates/guns-v8-biz/backend/main-table/request-pojo.java.btl")));
        mainTable.add(new GeneratorTemplate("/pojo/response", "Response.java", getResourceContent("templates/guns-v8-biz/backend/main-table/response-pojo.java.btl")));
        mainTable.add(new GeneratorTemplate("/service", "Service.java", getResourceContent("templates/guns-v8-biz/backend/main-table/service.java.btl")));
        mainTable.add(new GeneratorTemplate("/service/impl", "ServiceImpl.java", getResourceContent("templates/guns-v8-biz/backend/main-table/service-impl.java.btl")));
        bizGeneratorTemplateGroup.setBackendMainTableGeneratorTemplates(mainTable);

        List<GeneratorTemplate> oneToOne = createCommonOneToXTemplate();
        oneToOne.add(new GeneratorTemplate("/mapper", "Mapper.java", getResourceContent("templates/guns-v8-biz/backend/one-to-one/mapper.java.btl")));
        oneToOne.add(new GeneratorTemplate("/mapper/mapping", "Mapper.xml", getResourceContent("templates/guns-v8-biz/backend/one-to-one/mapping.xml.btl")));
        oneToOne.add(new GeneratorTemplate("/service", "Service.java", getResourceContent("templates/guns-v8-biz/backend/one-to-one/service.java.btl")));
        oneToOne.add(new GeneratorTemplate("/service/impl", "ServiceImpl.java", getResourceContent("templates/guns-v8-biz/backend/one-to-one/service-impl.java.btl")));
        bizGeneratorTemplateGroup.setBackendOneToOneGeneratorTemplates(oneToOne);

        List<GeneratorTemplate> oneToMany = createCommonOneToXTemplate();
        oneToMany.add(new GeneratorTemplate("/mapper", "Mapper.java", getResourceContent("templates/guns-v8-biz/backend/one-to-many/mapper.java.btl")));
        oneToMany.add(new GeneratorTemplate("/mapper/mapping", "Mapper.xml", getResourceContent("templates/guns-v8-biz/backend/one-to-many/mapping.xml.btl")));
        oneToMany.add(new GeneratorTemplate("/service", "Service.java", getResourceContent("templates/guns-v8-biz/backend/one-to-many/service.java.btl")));
        oneToMany.add(new GeneratorTemplate("/service/impl", "ServiceImpl.java", getResourceContent("templates/guns-v8-biz/backend/one-to-many/service-impl.java.btl")));
        bizGeneratorTemplateGroup.setBackendOneToManyGeneratorTemplates(oneToMany);

        return bizGeneratorTemplateGroup;
    }

    private static List<GeneratorTemplate> createCommonOneToXTemplate() {
        List<GeneratorTemplate> oneToMany = new ArrayList<>();

        oneToMany.add(new GeneratorTemplate("/entity", ".java", getResourceContent("templates/guns-v8-biz/backend/common/entity.java.btl")));
        oneToMany.add(new GeneratorTemplate("/enums", "ExceptionEnum.java", getResourceContent("templates/guns-v8-biz/backend/common/enum.java.btl")));

        return oneToMany;
    }

}
