package at.fos.ermodel.gui;

import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;

import java.io.Serial;


public abstract class Graphic_ATTR_Elem
        extends Graphic_Figure_Elem
        implements U2 {
    @Serial
    private static final long serialVersionUID = 1L;
    protected boolean createColumn;
    protected String columnPostfix;
    protected String columnName;
    protected String mvRelationname;
    protected String mvRelationnamePraefix;
    protected String datatype;
    protected boolean isKey;
    protected boolean isAutoincrement;
    protected long autoincrementStartAt;
    protected boolean isNullable;
    protected boolean isUnique;
    protected String dataGenerationType;
    protected String par1;
    protected String par2;
    protected String par1_label;
    protected String par2_label;
    boolean derived = false;

    public Graphic_ATTR_Elem(GraphicsContext gc, double x, double y, String name, long elementID) {
        super(gc, name, elementID);

        this.xPos = x;
        this.yPos = y;
        this.createColumn = true;
        this.columnName = T3.replaceSpecialChars(this.name.toLowerCase());
        if (this instanceof Graphic_ATTR_Multi_Elem) {
            this.mvRelationname = this.columnName + "_mvt";
            this.mvRelationnamePraefix = this.mvRelationname.charAt(0) + "_";
            this.createColumn = false;
        }
        this.columnPostfix = "";
        this.datatype = "varchar(100)";
        if(this.name.equalsIgnoreCase("id")) {
            this.datatype = "int";
        }
        this.isAutoincrement = false;

        this.isKey = this instanceof Graphic_ATTR_Key_Elem || this instanceof Graphic_ATTR_Weak_Key_Elem;
        if (this.isKey) this.isNullable = false;
        this.isUnique = false;
        this.dataGenerationType = "No";
    }


    protected void changeName(String name) {
        super.changeName(name);


        this.createColumn = true;
        this.columnName = T3.replaceSpecialChars(name.toLowerCase());
        if (this instanceof Graphic_ATTR_Multi_Elem) {
            this.createColumn = false;
            this.mvRelationname = this.columnName + "_mvt";
            this.mvRelationnamePraefix = this.mvRelationname.charAt(0) + "_";
        }
        this.columnPostfix = "";
        this.datatype = "varchar(100)";
        this.isAutoincrement = false;
        this.isKey = this instanceof Graphic_ATTR_Key_Elem || this instanceof Graphic_ATTR_Weak_Key_Elem;
        if (this.isKey) this.isNullable = false;
        this.isUnique = false;
    }


    public void dsfsdfsfd() {
        this.gc.clearRect(this.xPos - this.textWidth / 2.0D - 2.0D, this.yPos - this.textHeight / 2.0D - 2.0D, this.textWidth + 4.0D, this.textHeight + 4.0D);
    }


    public char sdfsdfdsfdf() {
        return 'a';
    }


    protected Color sefdsfdsf45() {
        return C2.ERMATTRColor;
    }


    protected Color getColorSelected() {
        return C2.ERMSelectedColor;
    }


    public boolean getCreateColumn() {
        return this.createColumn;
    }


    public void setCreateColumn(boolean createColumn) {
        this.createColumn = createColumn;
    }


    public String getColumnPostfix() {
        return this.columnPostfix;
    }


    public void setColumnPostfix(String columnPraefix) {
        this.columnPostfix = columnPraefix;
    }


    public String getColumnName() {
        return this.columnName;
    }


    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }


    public String getDatatype() {
        return this.datatype;
    }


    public void setDatatype(String datatype) {
        this.datatype = datatype;
    }


    public boolean isKey() {
        return this.isKey;
    }


    public void setIsKey(boolean isKey) {
        this.isKey = isKey;
    }


    public boolean isAutoincrement() {
        return this.isAutoincrement;
    }


    public void setIsAutoincrement(boolean isAutoincrement) {
        this.isAutoincrement = isAutoincrement;
    }


    public long getAutoincrementStartAt() {
        return this.autoincrementStartAt;
    }


    public void setAutoincrementStartAt(long autoincrementStartAt) {
        this.autoincrementStartAt = autoincrementStartAt;
    }


    public boolean isUnique() {
        return this.isUnique;
    }


    public void setIsUnique(boolean isUnique) {
        this.isUnique = isUnique;
    }


    public boolean isNullable() {
        return this.isNullable;
    }


    public void setIsNullable(boolean isNullable) {
        this.isNullable = isNullable;
    }


    public String getMVRelationName() {
        return this.mvRelationname;
    }


    public void setMVRelationName(String mvRelationname) {
        this.mvRelationname = mvRelationname;
    }


    public String getMVRelationNamePraefix() {
        return this.mvRelationnamePraefix;
    }


    public void setMVRelationNamePraefix(String mvRelationnamePraefix) {
        this.mvRelationnamePraefix = mvRelationnamePraefix;
    }


    public String sdfsdfsd32234243() {
        return this.name + "@" + this.datatype;
    }


    public String getDataGenerationType() {
        return this.dataGenerationType;
    }


    public void setDataGenerationType(String dataGenerationType) {
        this.dataGenerationType = dataGenerationType;
    }


    public String getPar1() {
        return this.par1;
    }


    public void setPar1(String par1) {
        this.par1 = par1;
    }


    public String getPar2() {
        return this.par2;
    }


    public void setPar2(String par2) {
        this.par2 = par2;
    }


    public String getPar1_label() {
        return this.par1_label;
    }


    public void setPar1_label(String par1_label) {
        this.par1_label = par1_label;
    }


    public String getPar2_label() {
        return this.par2_label;
    }


    public void setPar2_label(String par2_label) {
        this.par2_label = par2_label;
    }

    public void dsfdsfds6787686(Color c) {
        if (!this.isVisible) {
            return;
        }
        this.gc.beginPath();
        this.gc.setStroke(c);
        if (this.derived) {
            this.gc.setLineWidth(1.0D);
            this.gc.setLineDashes(3.0D);
        }
        this.gc.strokeOval(this.xPos - this.textWidth / 2.0D, this.yPos - this.textHeight / 2.0D, this.textWidth, this.textHeight);
        this.gc.setLineDashes();


        this.gc.setFill(C2.ERMTextColor);
        this.gc.fillText(this.name, this.xPos - this.textWidth / 2.0D + 10.0D, this.yPos + this.textHeight / 2.0D - 15.0D);
        this.gc.closePath();
    }

    public void setDerived(boolean derived) {
        this.derived = derived;
    }
}


