#pragma once

#include <cstdint>
#include <string>

namespace openpower
{
namespace software
{
namespace image
{

/** @class MinimumShipLevel
 *  @brief Contains minimum ship level verification functions.
 */
class MinimumShipLevel
{
  public:
    MinimumShipLevel() = delete;
    MinimumShipLevel(const MinimumShipLevel&) = delete;
    MinimumShipLevel& operator=(const MinimumShipLevel&) = delete;
    MinimumShipLevel(MinimumShipLevel&&) = default;
    MinimumShipLevel& operator=(MinimumShipLevel&&) = default;
    ~MinimumShipLevel() = default;

    /** @brief Constructs MinimumShipLevel.
     *  @param[in] minShipLevel - Minimum Ship Level string
     */
    explicit MinimumShipLevel(const std::string& minShipLevel) :
        minShipLevel(minShipLevel) {};

    /** @brief Verify if the current PNOR version meets the min ship level
     *  @return true if the verification succeeded, false otherwise
     */
    bool verify();

    /** @brief Version components */
    struct Version
    {
        uint8_t major;
        uint8_t minor;
        uint8_t rev;
    };

    /** @brief Get the functional PNOR version on the system
     *  @details If the PNOR version file is not found, don't log an error since
     *           all PNOR images may had been deleted. If there is an issue with
     *           the VERSION partition, it should be caught by the host fw code.
     *  @return The populated or empty version string
     */
    std::string getFunctionalVersion();

    /** @brief Parse the version components into a struct
     *  @details Version format follows a git tag convention: vX.Y[.Z]
     *          Reference:
     *          https://github.com/open-power/op-build/blob/master/openpower/package/VERSION.readme
     * @param[in]  versionStr - The version string to be parsed
     * @param[out] version    - The version struct to be populated
     */
    void parse(const std::string& versionStr, Version& version);

    /** @brief Compare the versions provided
     *  @param[in] a - The first version to compare
     *  @param[in] b - The second version to compare
     *  @return 1 if a > b
     *          0 if a = b
     *         -1 if a < b
     */
    int compare(const Version& a, const Version& b);

  private:
    /** Minimum Ship Level to compare against */
    std::string minShipLevel;
};

} // namespace image
} // namespace software
} // namespace openpower
