package xyz.wbsite.dbtool.javafx.po;

import javafx.scene.control.TreeItem;
import xyz.wbsite.dbtool.javafx.annotation.Property;

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

public class Module extends TreeItem {
    public Module() {
        setExpanded(true);
    }

    public Module(String moduleName) {
        setModuleName(moduleName);
        setExpanded(true);
    }

    @Property("name")
    private String moduleName;
    @Property("note")
    private String moduleComment;
    @Property("prefix")
    private String modulePrefix;
    @Property("needGenerate")
    private boolean needGenerate;

    private String projectName;
    private String projectBasePackage;
    private String projectAuthor;

    private List<Table> tables = new ArrayList();


    public String getModuleName() {
        return moduleName;
    }

    public void setModuleName(String moduleName) {
        this.moduleName = moduleName;
        this.setValue(moduleName);
    }

    public boolean putTable(Table table) {
        if (tables == null) {
            tables = new ArrayList<Table>();
        }
        tables.add(table);
        return true;
    }

    public boolean hasHtml() {
        for (Table table : tables) {
            if (table.getHtml()) return true;
        }
        return false;
    }

    public List<Table> getTables() {
        return tables;
    }

    public void setTables(List<Table> tables) {
        this.tables = tables;
    }

    public String getModuleComment() {
        return moduleComment;
    }

    public void setModuleComment(String moduleComment) {
        this.moduleComment = moduleComment;
    }

    public String getModulePrefix() {
        return modulePrefix;
    }

    public void setModulePrefix(String modulePrefix) {
        this.modulePrefix = modulePrefix != null ? modulePrefix : "";
    }

    public String getProjectName() {
        return projectName;
    }

    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

    public String getProjectBasePackage() {
        return projectBasePackage;
    }

    public void setProjectBasePackage(String projectBasePackage) {
        this.projectBasePackage = projectBasePackage;
    }

    public String getProjectAuthor() {
        return projectAuthor;
    }

    public void setProjectAuthor(String projectAuthor) {
        this.projectAuthor = projectAuthor;
    }

    public boolean getNeedGenerate() {
        return needGenerate;
    }

    public void setNeedGenerate(boolean needGenerate) {
        this.needGenerate = needGenerate;
    }
}
