/*
 * Copyright (c) Contributors to the Open 3D Engine Project.
 * For complete copyright and license terms please see the LICENSE at the root of this distribution.
 *
 * SPDX-License-Identifier: Apache-2.0 OR MIT
 *
 */

#pragma once

#include <Artifact/Dynamic/TestImpactCoverage.h>

#include <AzCore/std/containers/vector.h>
#include <AzCore/std/containers/unordered_map.h>

namespace TestImpact
{
    //! Scope of coverage data.
    enum class CoverageLevel : AZ::u8
    {
        Module, //!< Module-level coverage data.
        Source, //!< Line-level coverage data.
        Line //!< Source-level coverage data.
    };

    //! Representation of test coverage results.
    class TestCoverage
    {
    public:
        TestCoverage(const TestCoverage&);
        TestCoverage(TestCoverage&&) noexcept;
        TestCoverage(AZStd::vector<ModuleCoverage>&& moduleCoverages) noexcept;
        TestCoverage(const AZStd::vector<ModuleCoverage>& moduleCoverages);

        TestCoverage& operator=(const TestCoverage&);
        TestCoverage& operator=(TestCoverage&&) noexcept;

        virtual ~TestCoverage() = default;

        //! Returns the number of unique sources covered.
        size_t GetNumSourcesCovered() const;

        //! Returns the number of modules (dynamic libraries, child processes, etc.) covered.
        size_t GetNumModulesCovered() const;

        //! Returns the sorted set of unique sources covered (empty if no coverage).
        const AZStd::vector<RepoPath>& GetSourcesCovered() const;

        //! Returns the modules covered (empty if no coverage).
        const AZStd::vector<ModuleCoverage>& GetModuleCoverages() const;

        //! Returns the coverage level (empty if no coverage).
        AZStd::optional<CoverageLevel> GetCoverageLevel() const;

    private:
        void CalculateTestMetrics();

        AZStd::vector<ModuleCoverage> m_modules;
        AZStd::vector<RepoPath> m_sourcesCovered;
        AZStd::optional<CoverageLevel> m_coverageLevel;
    };

    //! Representation of per test case coverage results.
    using TestCaseCoverage = AZStd::unordered_map<AZStd::string, TestCoverage>;
} // namespace TestImpact
