/*
 * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION &
 * AFFILIATES. All rights reserved.
 * SPDX-License-Identifier: Apache-2.0
 */

#pragma once
#include "Thresholds.hpp"

#include <boost/asio/io_context.hpp>
#include <boost/asio/random_access_file.hpp>
#include <boost/asio/steady_timer.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/asio/object_server.hpp>
#include <sensor.hpp>

#include <array>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include <vector>

constexpr std::array<size_t, 3> i2CReadLenValues = {4, 8, 8};

enum class I2C_READ_LEN_INDEX
{
    FLOAT32,
    FLOAT64,
    UINT64
};

struct SmbpbiSensor : public Sensor
{
    SmbpbiSensor(
        std::shared_ptr<sdbusplus::asio::connection>& conn,
        boost::asio::io_context& io, const std::string& name,
        const std::string& sensorConfiguration, const std::string& objType,
        sdbusplus::asio::object_server& objectServer,
        std::vector<thresholds::Threshold>&& thresholdData, uint8_t busId,
        uint8_t addr, uint16_t offset, std::string& sensorUnits,
        std::string& valueType, size_t pollTime, double minVal, double maxVal,
        std::string& path);
    ~SmbpbiSensor() override;

    void checkThresholds() override;

    size_t getPollRate() const
    {
        return pollRateSecond;
    }
    void read();
    void init();

    uint8_t busId;
    uint8_t addr;
    uint16_t offset;
    std::string sensorUnits;
    std::string sensorType;
    std::string valueType;

  private:
    int i2cReadDataBytes(uint8_t* reading, int length);
    int i2cReadDataBytesDouble(double& reading);
    int i2cReadDataBytesUI64(uint64_t& reading);
    int readRawEEPROMData(double& data);
    int readFloat64EEPROMData(double& data);
    static double convert2Temp(const uint8_t* rawData);
    static double convert2Power(const uint8_t* rawData);
    void waitReadCallback(const boost::system::error_code& ec);
    sdbusplus::asio::object_server& objectServer;
    boost::asio::random_access_file inputDev;
    boost::asio::steady_timer waitTimer;
    size_t pollRateSecond;
};

bool checkInvalidReading(uint8_t* reading, int length)
{
    // there is no value updated from HMC if reading data is all 0xff
    uint8_t* ptr = reading;
    for (int i = 0; i < length; i++, ptr++)
    {
        if (*ptr != 0xFF)
        {
            return false;
        }
    }
    return true;
}
