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 Project extends TreeItem {

    public Project() {
        this.name = "example-web";
        this.domain = "com.example";
        this.author = "author";
        this.frame = Frame.网页框架;
        this.database = DataBase.MySQL;
        this.needEMail = false;
        this.needCloud = false;
    }

    public Project(String name) {
        this.name = name;
        setValue(name);
        setExpanded(true);
    }

    @Property("name")
    private String name;
    @Property("domain")
    private String domain;
    @Property("author")
    private String author;
    @Property(value = "frame")
    private Frame frame;
    @Property(value = "database")
    private DataBase database;
    @Property("needMoreDB")
    private boolean needMoreDB;
    @Property("needEMail")
    private boolean needEMail;
    @Property("needCloud")
    private boolean needCloud;
    @Property("needAsync")
    private boolean needAsync;

    /**
     * 对象
     */
    private List<Module> modules = new ArrayList();

    public boolean putModule(Module module) {
        modules.add(module);
        this.getChildren().add(module);
        return true;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
        this.setValue(name);
    }

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public List<Module> getModules() {
        return modules;
    }

    public void setModules(List<Module> modules) {
        this.modules = modules;
    }

    public boolean isNeedMoreDB() {
        return needMoreDB;
    }

    public void setNeedMoreDB(boolean needMoreDB) {
        this.needMoreDB = needMoreDB;
    }

    public boolean isNeedCloud() {
        return needCloud;
    }

    public void setNeedCloud(boolean needCloud) {
        this.needCloud = needCloud;
    }

    public DataBase getDatabase() {
        return database;
    }

    public void setDatabase(DataBase database) {
        this.database = database;
    }

    public boolean isNeedEMail() {
        return needEMail;
    }

    public void setNeedEMail(boolean needEMail) {
        this.needEMail = needEMail;
    }

    public boolean isNeedAsync() {
        return needAsync;
    }

    public void setNeedAsync(boolean needAsync) {
        this.needAsync = needAsync;
    }

    public Frame getFrame() {
        return frame;
    }

    public void setFrame(Frame frame) {
        this.frame = frame;
    }

    public int frameValue() {
        return frame.value();
    }

    public boolean isNeedApi() {
        for (Module module : modules) {
            for (Table table : module.getTables()) {
                if (table.getApi()) {
                    return true;
                }
            }
        }
        return false;
    }
}
