/*
    SPDX-FileCopyrightText: 2008 Friedrich W. H. Kossebau <kossebau@kde.org>

    SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/

#ifndef KPIECETABLE_TESTPIECETABLECHANGE_HPP
#define KPIECETABLE_TESTPIECETABLECHANGE_HPP

// lib
#include <piecetable/abstractpiecetablechange.hpp>
#include <piecetable/piece.hpp>
// Qt
#include <QString>

namespace KPieceTable {

class TestPieceTableChange : public AbstractPieceTableChange
{
public:
    explicit
    TestPieceTableChange(int typeId = -1, const QString& description = QString(),
                         Address position = 0, Address storagePosition = 0, Piece::StorageType storageId = Piece::ChangeStorage,
                         Address replacedStoragePosition = 0, Piece::StorageType replacedStorageId = Piece::ChangeStorage);

    ~TestPieceTableChange() override;

public: // AbstractPieceTableChange API
    [[nodiscard]]
    int type() const override;
    [[nodiscard]]
    QString description() const override;
    [[nodiscard]]
    bool merge(const AbstractPieceTableChange* other) override;
    [[nodiscard]]
    AddressRange apply(PieceTable* pieceTable) const override;
    [[nodiscard]]
    AddressRange revert(PieceTable* pieceTable) const override;
    [[nodiscard]]
    ArrayChangeMetrics metrics() const override;
    [[nodiscard]]
    int dataSize() const override;

private:
    int mTypeId;
    QString mDescription;
    Address mPosition;
    Address mStoragePosition;
    Piece::StorageType mStorageId;

    Address mReplacedStoragePosition;
    Piece::StorageType mReplacedStorageId;
};

inline TestPieceTableChange::TestPieceTableChange(int typeId, const QString& description,
                                                  Address position, Address storagePosition, Piece::StorageType storageId,
                                                  Address replacedStoragePosition, Piece::StorageType replacedStorageId)
    : mTypeId(typeId)
    , mDescription(description)
    , mPosition(position)
    , mStoragePosition(storagePosition)
    , mStorageId(storageId)
    , mReplacedStoragePosition(replacedStoragePosition)
    , mReplacedStorageId(replacedStorageId)
{}

}

#endif
