#ifndef QPAGEDTABLECOLUMN_H
#define QPAGEDTABLECOLUMN_H

#include <QObject>
#include <QHeaderView>

class QPagedTableColumn
{
public:
    QPagedTableColumn() {};
    QPagedTableColumn(QMap<QString, QVariant> colMap) {
        idx = colMap.value("idx").toInt();
        name = colMap.value("name").toString();
        text = colMap.value("text").toString();
        value = colMap.value("value").toString();

        setWidthType(colMap.value("widthType").toString());
        setAlignType(colMap.value("align").toString());
        setResizeMode(colMap.value("resizeMode").toString());

        width = colMap.value("width").toDouble();
    }

    enum ColumnWidthType {
        PIXEL,
        PERCENT
    };

    int idx;
    QString name;
    QString text;
    QString value;
    double width;

    int widthType = ColumnWidthType::PERCENT;
    int align = Qt::AlignmentFlag::AlignCenter;
    int resizeMode = QHeaderView::ResizeMode::Fixed;

    void setWidthType(QString type) {
        type = type.toUpper();
        if (type.isEmpty()) {
            widthType = ColumnWidthType::PIXEL;
        }

        if (type == "PIXEL") {
            widthType = ColumnWidthType::PIXEL;
        } else if (type == "PERCENT") {
            widthType = ColumnWidthType::PERCENT;
        }
    }

    void setAlignType(QString type) {
        type = type.toUpper();
        if (type.isEmpty()) {
            align = Qt::AlignmentFlag::AlignCenter;
        }

        if (type == "LEFT") {
            align = Qt::AlignmentFlag::AlignLeft | Qt::AlignmentFlag::AlignVCenter;
        } else if (type == "CENTER") {
            align = Qt::AlignmentFlag::AlignCenter;
        } else if (type == "RIGHT") {
            align = Qt::AlignmentFlag::AlignRight | Qt::AlignmentFlag::AlignVCenter;
        }
    }

    void setResizeMode(QString type) {
        type = type.toUpper();
        if (type.isEmpty()) {
            resizeMode = QHeaderView::ResizeMode::Fixed;
        }

        if (type == "STRETCH") {
            resizeMode = QHeaderView::ResizeMode::Stretch;
        } else if (type == "FIXED") {
            resizeMode = QHeaderView::ResizeMode::Fixed;
        } else if (type == "CONTENTS") {
            resizeMode = QHeaderView::ResizeMode::ResizeToContents;
        }
    }

};

#endif // QPAGEDTABLECOLUMN_H
