package dev.fyloz.trial.colorrecipesexplorer.xlsx.component.cells;

import dev.fyloz.trial.colorrecipesexplorer.xlsx.component.cells.styles.IBiggerCell;
import dev.fyloz.trial.colorrecipesexplorer.xlsx.component.cells.styles.IColoredCell;
import dev.fyloz.trial.colorrecipesexplorer.xlsx.component.cells.styles.IFontCell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.IndexedColors;

public class DescriptionCell extends Cell implements IColoredCell, IBiggerCell, IFontCell {

    private static final int WIDTH_NAME = 2;
    private static final int WIDTH_VALUE = 6;
    private static final int HEIGHT = 2;
    private static final IndexedColors BG_COLOR_NAME = IndexedColors.GREY_40_PERCENT;
    private static final short FONT_HEIGHT = 18;

    private DescriptionCellType type;
    private String valueStr;
    private double valueNbr;

    public DescriptionCell(DescriptionCellType type, String value) {
        super(CellType.STRING);

        this.type = type;
        this.valueStr = value;
    }

    public DescriptionCell(DescriptionCellType type, double value) {
        super(CellType.NUMERIC);

        this.type = type;
        this.valueNbr = value;
    }

    @Override
    public int getWidth() {
        return type == DescriptionCellType.NAME ? WIDTH_NAME : WIDTH_VALUE;
    }

    @Override
    public int getHeight() {
        return HEIGHT;
    }

    @Override
    public IndexedColors getBackgroundColor() {
        return type == DescriptionCellType.NAME ? BG_COLOR_NAME : IndexedColors.WHITE1;
    }

    @Override
    public short getFontHeight() {
        return FONT_HEIGHT;
    }

    @Override
    public String getContentText() {
        return type != DescriptionCellType.VALUE_NUM ? valueStr : "";
    }

    @Override
    public double getContentNum() {
        return type == DescriptionCellType.VALUE_NUM ? valueNbr : 0.0d;
    }

    public enum DescriptionCellType {
        NAME, VALUE_STR, VALUE_NUM
    }
}
