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

import dev.fyloz.trial.colorrecipesexplorer.config.Preferences;
import dev.fyloz.trial.colorrecipesexplorer.xlsx.builder.SheetBuilder;
import dev.fyloz.trial.colorrecipesexplorer.xlsx.exception.InvalidCellTypeException;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbookType;

public class Document extends XSSFWorkbook {

    public static final int WIDTH = 8;
    private static final XSSFWorkbookType WORKBOOK_TYPE = XSSFWorkbookType.XLSX;

    private Sheet sheet;

    public Document(String name) {
        super(WORKBOOK_TYPE);

        sheet = new Sheet(this, createSheet(name));
    }

    public void buildSheet() {
        try {
            new SheetBuilder(sheet).build();
        } catch (InvalidCellTypeException e) {
            Preferences.logger.error("Une erreur est survenue lors de la génération du document: " + e.getLocalizedMessage());
        }
    }

    public Sheet getSheet() {
        return sheet;
    }
}
