#pragma once

#include "filedescriptor.hpp"

#include <memory>
#include <vector>

namespace openpower
{
namespace targeting
{

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

constexpr auto fsiSlaveBaseDir = "/sys/class/fsi-master/fsi1/";

/**
 * 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), cfamPath(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 CFAM sysfs path
     */
    inline auto getCFAMPath() const
    {
        return cfamPath;
    }

    /**
     * Returns the file descriptor to use
     * for read/writeCFAM operations.
     */
    int getCFAMFD();

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

    /**
     * The sysfs device path for the CFAM
     */
    const std::string cfamPath;

    /**
     * The file descriptor to use for read/writeCFAMReg
     */
    std::unique_ptr<openpower::util::FileDescriptor> cfamFD;
};

/**
 * 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();
    }

    /**
     * Returns a target by position.
     */
    std::unique_ptr<Target>& getTarget(size_t pos);

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

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

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

} // namespace targeting
} // namespace openpower
