/* -*- mode: c++; c-basic-offset:4 -*-
    crypto/signencrypttask.h

    This file is part of Kleopatra, the KDE keymanager
    SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB

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

#pragma once

#include <crypto/task.h>

#include <gpgme++/global.h>

#include <memory>
#include <vector>

class QString;

namespace GpgME
{
class EncryptionResult;
class Key;
class SigningResult;
}

namespace Kleo
{
class OverwritePolicy;
class Input;
class Output;
}

namespace Kleo
{
namespace Crypto
{
namespace _detail
{
struct LabelAndError;
}

class SignEncryptTask : public Task
{
    Q_OBJECT
public:
    explicit SignEncryptTask(QObject *parent = nullptr);
    ~SignEncryptTask() override;

    void setInputFileName(const QString &fileName);
    void setInputFileNames(const QStringList &fileNames);
    void setInput(const std::shared_ptr<Input> &input);
    void setOutput(const std::shared_ptr<Output> &output);
    void setOutputFileName(const QString &fileName);
    QString outputFileName() const;
    void setSigners(const std::vector<GpgME::Key> &signers);
    void setRecipients(const std::vector<GpgME::Key> &recipients);

    void setSign(bool sign);
    void setEncrypt(bool encrypt);
    void setDetachedSignature(bool detached);
    bool detachedSignatureEnabled() const;
    void setEncryptSymmetric(bool symmetric);
    void setClearsign(bool clearsign);
    void setCreateArchive(bool archive);
    void setAlwaysTrust(bool alwaysTrust);

    void setOverwritePolicy(const std::shared_ptr<OverwritePolicy> &policy);
    GpgME::Protocol protocol() const override;

    void cancel() override;
    QString label() const override;
    QString tag() const override;

private:
    void doStart() override;
    unsigned long long inputSize() const override;

private:
    class Private;
    const std::unique_ptr<Private> d;
    Q_PRIVATE_SLOT(d, void slotResult(const GpgME::SigningResult &))
    Q_PRIVATE_SLOT(d, void slotResult(const GpgME::SigningResult &, const GpgME::EncryptionResult &))
    Q_PRIVATE_SLOT(d, void slotResult(const GpgME::EncryptionResult &))
};

class SignEncryptTaskResult : public Task::Result
{
    friend class ::Kleo::Crypto::SignEncryptTask;

private:
    SignEncryptTaskResult(const GpgME::SigningResult &sr,
                          const GpgME::EncryptionResult &er,
                          const _detail::LabelAndError &input,
                          const _detail::LabelAndError &output,
                          bool outputCreated,
                          const AuditLogEntry &auditLog,
                          Task *parentTask);

public:
    QString overview() const override;
    QString details() const override;
    GpgME::Error error() const override;
    QString errorString() const override;
    VisualCode code() const override;
    AuditLogEntry auditLog() const override;

    GpgME::SigningResult signingResult() const;
    GpgME::EncryptionResult encryptionResult() const;

private:
    class Private;
    const std::unique_ptr<Private> d;
};
}
}
