/*
    SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com>

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

#pragma once

#include "akonadi-mime_export.h"

#include <QDateTime>

#include <Akonadi/Attribute>

#include <memory>

namespace Akonadi
{
class DispatchModeAttributePrivate;

/*!
  \class Akonadi::DispatchModeAttribute
  \inmodule AkonadiMime
  \inheaderfile Akonadi/DispatchModeAttribute

  Attribute determining how and when a message from the outbox should be
  dispatched.  Messages can be sent immediately, sent only when the user
  explicitly requests it, or sent automatically at a certain date and time.

  \author Constantin Berzan <exit3219@gmail.com>
  \since 4.4
*/
class AKONADI_MIME_EXPORT DispatchModeAttribute : public Akonadi::Attribute
{
public:
    /*!
      Determines how the message is sent.
    */
    enum DispatchMode {
        Automatic, ///< Send message as soon as possible, but no earlier than
        ///  specified by setSendAfter()
        Manual ///< Send message only when the user requests so.
    };

    /*!
      Creates a new DispatchModeAttribute.
    */
    explicit DispatchModeAttribute(DispatchMode mode = Automatic);

    /*!
      Destroys the DispatchModeAttribute.
    */
    ~DispatchModeAttribute() override;

    /*!
      Returns a copy of this attribute.
    */
    DispatchModeAttribute *clone() const override;
    /*!
      Returns the type of the attribute.
    */
    [[nodiscard]] QByteArray type() const override;
    /*!
      Returns the serialized representation of the attribute.
    */
    [[nodiscard]] QByteArray serialized() const override;
    /*!
      Deserializes the attribute from the given data.
      \a data the serialized data
    */
    void deserialize(const QByteArray &data) override;

    /*!
      Returns the dispatch mode for the message.
      \sa DispatchMode.
    */
    [[nodiscard]] DispatchMode dispatchMode() const;

    /*!
      Sets the dispatch mode for the message.
      \a mode the dispatch mode to set
      \sa DispatchMode.
    */
    void setDispatchMode(DispatchMode mode);

    /*!
      Returns the date and time when the message should be sent.
      Only valid if dispatchMode() is Automatic.
    */
    [[nodiscard]] QDateTime sendAfter() const;

    /*!
      Sets the date and time when the message should be sent.
      \a date the date and time to set
      \sa setDispatchMode.
    */
    void setSendAfter(const QDateTime &date);

private:
    std::unique_ptr<DispatchModeAttributePrivate> const d;
};
} // namespace MailTransport
