// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#pragma once

#include "cmakebuildtarget.h"
#include "cmakeconfigitem.h"

#include <projectexplorer/projectnodes.h>

namespace CMakeProjectManager::Internal {

class CMakeInputsNode : public ProjectExplorer::ProjectNode
{
public:
    CMakeInputsNode(const Utils::FilePath &cmakeLists);
};

class CMakePresetsNode : public ProjectExplorer::ProjectNode
{
public:
    CMakePresetsNode(const Utils::FilePath &projectPath);
};

class CMakeListsNode : public ProjectExplorer::ProjectNode
{
    bool m_hasSubprojectBuildSupport{false};

public:
    CMakeListsNode(const Utils::FilePath &cmakeListPath);

    bool showInSimpleTree() const final;
    std::optional<Utils::FilePath> visibleAfterAddFileAction() const override;

    bool canAddSubProject(const Utils::FilePath &subProjectFilePath) const override;
    bool addSubProject(const Utils::FilePath &subProjectFilePath) override;
    QStringList subProjectFileNamePatterns() const override;

    bool canBuild(ProjectExplorer::BuildAction) override { return m_hasSubprojectBuildSupport; }
    void build(ProjectExplorer::BuildAction action) override;

    bool hasSubprojectBuildSupport() const;
    void setHasSubprojectBuildSupport(bool hasSubprojectBuildSupport);
};

class CMakeProjectNode : public ProjectExplorer::ProjectNode
{
public:
    CMakeProjectNode(const Utils::FilePath &directory);

    bool canAddSubProject(const Utils::FilePath &subProjectFilePath) const override;
    bool addSubProject(const Utils::FilePath &subProjectFilePath) override;
    QStringList subProjectFileNamePatterns() const override;

    QString tooltip() const final;
};

class CMakeTargetNode : public ProjectExplorer::ProjectNode
{
public:
    CMakeTargetNode(const Utils::FilePath &directory, const CMakeBuildTarget &target);

    void setTargetInformation(const Utils::FilePaths &artifacts, const QString &type);

    QString tooltip() const final;
    QString buildKey() const final;
    Utils::FilePath buildDirectory() const;
    void setBuildDirectory(const Utils::FilePath &directory);

    std::optional<Utils::FilePath> visibleAfterAddFileAction() const override;

    void build(ProjectExplorer::BuildAction action) override;
    bool canBuild(ProjectExplorer::BuildAction action) override { return action == ProjectExplorer::BuildAction::Build; }

    QVariant data(Utils::Id role) const override;
    void setConfig(const CMakeConfig &config);

    CMakeBuildTarget cmakeBuildTarget() const;
    void setCMakeBuildTarget(const CMakeBuildTarget &cmakeBuildTarget);

    void setVisibleAfterAddFileAction(bool visibleAfterAddFileAction);

    using ProjectExplorer::Node::setFilePath;
private:
    QString m_tooltip;
    CMakeBuildTarget m_cmakeBuildTarget;
    Utils::FilePath m_buildDirectory;
    CMakeConfig m_config;
    bool m_visibleAfterAddFileAction = true;
};

} // CMakeProjectManager::Internal
