package com.ruoyi.generator.service.front;

import java.util.ArrayList;
import java.util.List;
import com.ruoyi.generator.domain.GenProject;
import com.ruoyi.generator.domain.GenTable;
import com.ruoyi.generator.domain.GenTableColumn;
import com.ruoyi.generator.domain.front.FrontProject;
import com.ruoyi.generator.domain.front.FrontProjectColumn;
import com.ruoyi.generator.domain.front.FrontProjectTable;

public class FrontProjectConverter
{
    public static GenProject toGenProject(FrontProject project)
    {
        if (project == null)
        {
            return null;
        }
        GenProject genProject = new GenProject();
        genProject.setProjectId(project.getProjectId());
        genProject.setProjectName(project.getProjectName());
        genProject.setProjectFileName(project.getProjectFileName());
        genProject.setPackageName(project.getPackageName());
        genProject.setVersion(project.getVersion());
        genProject.setProjectDesc(project.getProjectDesc());
        genProject.setFrontFramework(project.getFrontFramework());
        genProject.setBackFramework(project.getBackFramework());
        genProject.setStatus(project.getStatus());
        genProject.setTables(toGenTables(project.getTables()));
        return genProject;
    }

    private static List<GenTable> toGenTables(List<FrontProjectTable> tables)
    {
        List<GenTable> genTables = new ArrayList<GenTable>();
        if (tables == null)
        {
            return genTables;
        }
        for (FrontProjectTable table : tables)
        {
            genTables.add(toGenTable(table));
        }
        return genTables;
    }

    private static GenTable toGenTable(FrontProjectTable table)
    {
        GenTable genTable = new GenTable();
        genTable.setTableId(table.getTableId());
        genTable.setTableName(table.getTableName());
        genTable.setTableComment(table.getTableComment());
        genTable.setClassName(table.getClassName());
        genTable.setModuleName(table.getModuleName());
        genTable.setBusinessName(table.getBusinessName());
        genTable.setFunctionName(table.getFunctionName());
        genTable.setTplCategory(table.getTplCategory());
        genTable.setTplWebType(table.getTplWebType());
        genTable.setOptions(table.getOptions());
        genTable.setCreateTableSql(table.getCreateTableSql());
        genTable.setColumns(toGenColumns(table.getColumns()));
        return genTable;
    }

    private static List<GenTableColumn> toGenColumns(List<FrontProjectColumn> columns)
    {
        List<GenTableColumn> genColumns = new ArrayList<GenTableColumn>();
        if (columns == null)
        {
            return genColumns;
        }
        for (FrontProjectColumn column : columns)
        {
            GenTableColumn genColumn = new GenTableColumn();
            genColumn.setColumnId(column.getColumnId());
            genColumn.setTableId(column.getTableId());
            genColumn.setColumnName(column.getColumnName());
            genColumn.setColumnComment(column.getColumnComment());
            genColumn.setColumnType(column.getColumnType());
            genColumn.setJavaType(column.getJavaType());
            genColumn.setJavaField(column.getJavaField());
            genColumn.setIsPk(column.getIsPk());
            genColumn.setIsIncrement(column.getIsIncrement());
            genColumn.setIsRequired(column.getIsRequired());
            genColumn.setIsInsert(column.getIsInsert());
            genColumn.setIsEdit(column.getIsEdit());
            genColumn.setIsList(column.getIsList());
            genColumn.setIsQuery(column.getIsQuery());
            genColumn.setQueryType(column.getQueryType());
            genColumn.setHtmlType(column.getHtmlType());
            genColumn.setDictType(column.getDictType());
            genColumn.setSort(column.getSort());
            genColumns.add(genColumn);
        }
        return genColumns;
    }
}
