#ifndef DESIGNATORMAPPINGTABLEMODEL_H
#define DESIGNATORMAPPINGTABLEMODEL_H

#include <QAbstractTableModel>
#include <QList>
#include "designatormappingmodel.h"

class DesignatorMappingTableModel : public QAbstractTableModel
{
    Q_OBJECT

public:
    explicit DesignatorMappingTableModel(DesignatorMappingModel *mappingModel, QObject *parent = nullptr);

    // QAbstractTableModel interface
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    int columnCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
    Qt::ItemFlags flags(const QModelIndex &index) const override;

    // Методы для работы с данными
    void addMapping(const DesignatorMappingItem &item);
    void removeMapping(int row);
    void updateMapping(int row, const DesignatorMappingItem &item);
    DesignatorMappingItem getMapping(int row) const;
    void refreshData();

    // Методы для фильтрации
    void setShowOnlyCustom(bool showOnly);
    void setFilterText(const QString &text);

private slots:
    void onMappingsChanged();

private:
    DesignatorMappingModel *m_mappingModel;
    QList<DesignatorMappingItem> m_filteredMappings;
    bool m_showOnlyCustom;
    QString m_filterText;

    void updateFilteredMappings();
    bool matchesFilter(const DesignatorMappingItem &item) const;

    enum Columns {
        Designator = 0,
        SingularName = 1,
        PluralName = 2,
        IsCustom = 3,
        ColumnCount = 4
    };
};

#endif // DESIGNATORMAPPINGTABLEMODEL_H 