#pragma once

#include <memory>
#include <vector>

namespace openpower
{
namespace targeting
{

constexpr auto fsiMasterDevPath =
    "/sys/devices/platform/fsi-master/slave@00:00/raw";

constexpr auto fsiSlaveBaseDir = "/sys/devices/hub@00/";

/**
 * Represents a specific P9 processor in the system.  Used by
 * the access APIs to specify the chip to operate on.
 */
class Target
{
    public:

        /**
         * Constructor
         *
         * @param[in] - The logical position of the target
         * @param[in] - The sysfs device path
         */
        Target(size_t position, const std::string& devPath) :
            pos(position), path(devPath)
        {
        }

        Target() = delete;
        ~Target() = default;
        Target(const Target&) = default;
        Target(Target&&) = default;
        Target& operator=(Target&&) = default;

        /**
         * Returns the position
         */
        inline auto getPos() const
        {
            return pos;
        }

        /**
         * Returns the path
         */
        inline auto getPath() const
        {
            return path;
        }

    private:

        /**
         * The logical position of this target
         */
        size_t pos;

        /**
         * The sysfs device path
         */
        const std::string path;
};


/**
 * Class that manages processor targeting for FSI operations.
 */
class Targeting
{
    public:

        /**
         * Scans sysfs to find all processors and creates Target objects
         * for them.
         * @param[in] fsiMasterDev - the sysfs device for the master
         * @param[in] fsiSlaveDirectory - the base sysfs dir for slaves
         */
        Targeting(const std::string& fsiMasterDev,
                  const std::string& fsiSlaveDir);

        Targeting() : Targeting(fsiMasterDevPath, fsiSlaveBaseDir) {}

        ~Targeting() = default;
        Targeting(const Targeting&) = default;
        Targeting(Targeting&&) = default;
        Targeting& operator=(Targeting&&) = default;

        /**
         * Returns a const iterator to the first target
         */
        inline auto begin()
        {
            return targets.cbegin();
        }

        /**
         * Returns a const iterator to the last (highest position) target.
         */
        inline auto end()
        {
            return targets.cend();
        }

        /**
         * Returns the number of targets
         */
        inline auto size()
        {
            return targets.size();
        }

    private:

        /**
         * The path to the fsi-master sysfs device to access
         */
        const std::string fsiMasterPath;

        /**
         * The path to the fsi slave sysfs base directory
         */
        const std::string fsiSlaveBasePath;

        /**
         * A container of Targets in the system
         */
        std::vector<std::unique_ptr<Target>> targets;
};

}
}
