/****************************************************************************
**
** Copyright (C) 2014 Jolla Ltd.
** Contact: http://jolla.com/
**
** This file is part of Qt Creator.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Digia.
**
****************************************************************************/

#ifndef NXTBUILDSTEPS_H
#define NXTBUILDSTEPS_H

#include <vm/nxtabstractvmstartstep.h>
#include <steps/build/nxtabstractbuildstep.h>

#include <qmakeprojectmanager/qmakeprojectmanagerconstants.h>
#include <libs/utils/fileutils.h>

#include <genericprojectmanager/genericmakestep.h>

namespace Nxt {
namespace Internal {

class NxtConnection;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class NxtSdkStartStep : public NxtAbstractVmStartStep
{
    Q_OBJECT

public:
    explicit NxtSdkStartStep(ProjectExplorer::BuildStepList *bsl);

    bool init(QList<const BuildStep *> &earlierSteps) override;

    static Core::Id stepId();
    static QString displayName();
};

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class NxtBundleStep : public ProjectExplorer::AbstractProcessStep
{
    Q_OBJECT

public:
    explicit NxtBundleStep(ProjectExplorer::BuildStepList *parent, const QString &buildTarget = {});

    bool init(QList<const BuildStep *> &earlierSteps) override;
    void run(QFutureInterface<bool> &fi) override;

    ProjectExplorer::BuildStepConfigWidget *createConfigWidget() override;
    bool immutable() const override;
    bool buildsTarget(const QString &target) const;
    void setBuildTarget(const QString &target, bool on);
    QString allArguments() const;
    QString makeCommand(const Utils::Environment &environment) const;

    void setClean(bool clean);
    bool isClean() const;

    static Core::Id stepId();
    static QString displayName();

private:
    QVariantMap toMap() const override;
    bool fromMap(const QVariantMap &map) override;

    QStringList m_buildTargets;
    QString m_makeCommand;
    QString m_makeArguments;
    bool m_clean = false;
};

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#if 0 /* NxtDeployStep */
class NxtDeployStep : public ProjectExplorer::AbstractProcessStep
{
    Q_OBJECT

public:
    explicit NxtDeployStep(ProjectExplorer::BuildStepList *parent, const QString &buildTarget = {});

    bool init(QList<const BuildStep *> &earlierSteps) override;
    void run(QFutureInterface<bool> &fi) override;

    ProjectExplorer::BuildStepConfigWidget *createConfigWidget() override;
    bool immutable() const override;
    bool buildsTarget(const QString &target) const;
    void setBuildTarget(const QString &target, bool on);
    QString allArguments() const;
    QString makeCommand(const Utils::Environment &environment) const;

    void setClean(bool clean);
    bool isClean() const;

    static Core::Id stepId();
    static QString displayName();

private:
    QVariantMap toMap() const override;
    bool fromMap(const QVariantMap &map) override;

    QStringList m_buildTargets;
    QString m_makeCommand;
    QString m_makeArguments;
    bool m_clean = false;
};
#endif /* NxtDeployStep */

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

template<class Step>
class NxtBuildStepFactory : public ProjectExplorer::BuildStepFactory
{
public:
    NxtBuildStepFactory()
    {
        registerStep<Step>(Step::stepId());
        setDisplayName(Step::displayName());
        setSupportedProjectType(QmakeProjectManager::Constants::QMAKEPROJECT_ID);
    }
};

} // namespace Internal
} // namespace Nxt

#endif // NXTBUILDSTEPS_H
