/*
    bodypartformatterfactory.h

    This file is part of KMail, the KDE mail client.
    SPDX-FileCopyrightText: 2004 Marc Mutz <mutz@kde.org>
    SPDX-FileCopyrightText: 2004 Ingo Kloecker <kloecker@kde.org>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

#pragma once

#include "mimetreeparser_export.h"

#include <QList>
#include <memory>
namespace MimeTreeParser
{
namespace Interface
{
class BodyPartFormatter;
}

class BodyPartFormatterFactoryPrivate;

/**
 * \class MimeTreeParser::BodyPartFormatterFactory
 * \inmodule MimeTreeParser
 * \inheaderfile MimeTreeParser/BodyPartFormatterFactory
 *
 * The place to obtain BodyPartFormatter candidates for a given mime type.
 */
class MIMETREEPARSER_EXPORT BodyPartFormatterFactory
{
public:
    /*!
     * \brief Constructor.
     */
    BodyPartFormatterFactory();
    /*!
     * \brief Destructor.
     */
    virtual ~BodyPartFormatterFactory();

    /*!
     * \brief Get singleton instance.
     * \return Pointer to the singleton instance.
     */
    static BodyPartFormatterFactory *instance();

    /*!
     * \brief Get formatters for MIME type.
     * Returns all suitable formatters for the given mimetype.
     * The candidates are ordered by priority, with the catch-call
     * formatter coming last.
     * \param mimeType The MIME type string.
     * \return List of BodyPartFormatter pointers.
     */
    [[nodiscard]] QList<const Interface::BodyPartFormatter *> formattersForType(const QString &mimeType) const;

protected:
    /*!
     * \brief Insert formatter.
     * \param mimeType The MIME type string.
     * \param formatter The BodyPartFormatter to insert.
     * \param priority The priority of the formatter.
     */
    void insert(const QString &mimeType, const Interface::BodyPartFormatter *formatter, int priority);
    /*!
     */
    virtual void loadPlugins();

private:
    Q_DISABLE_COPY(BodyPartFormatterFactory)
    std::unique_ptr<BodyPartFormatterFactoryPrivate> const d;
    friend class BodyPartFormatterFactoryPrivate;
};
}
