/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <PowerStats.h>

#include <android-base/chrono_utils.h>

#include <chrono>
#include <random>

namespace aidl {
namespace android {
namespace hardware {
namespace power {
namespace stats {

class FakeEnergyConsumer : public PowerStats::IEnergyConsumer {
  public:
    FakeEnergyConsumer(EnergyConsumerType type, std::string name) : mType(type), mName(name) {
        mResult.timestampMs = 0;
        mResult.energyUWs = 0;
        mResult.attribution = {};
    }

    ~FakeEnergyConsumer() = default;

    std::string getName() override { return mName; }

    EnergyConsumerType getType() override { return mType; }

    std::optional<EnergyConsumerResult> getEnergyConsumed() override {
        mFakeEnergyConsumerResult.update(&mResult);
        return mResult;
    }

  private:
    class FakeEnergyConsumerResult {
      public:
        FakeEnergyConsumerResult() : mDistribution(1, 100) {}
        void update(EnergyConsumerResult* result) {
            // generates number in the range 1..100
            auto randNum = std::bind(mDistribution, mGenerator);

            // Get current time since boot in milliseconds
            uint64_t now = std::chrono::time_point_cast<std::chrono::milliseconds>(
                                   ::android::base::boot_clock::now())
                                   .time_since_epoch()
                                   .count();
            result->timestampMs = now;
            result->energyUWs += randNum() * 100;
        }

      private:
        std::default_random_engine mGenerator;
        std::uniform_int_distribution<int> mDistribution;
    };

    EnergyConsumerType mType;
    std::string mName;
    FakeEnergyConsumerResult mFakeEnergyConsumerResult;
    EnergyConsumerResult mResult;
};

}  // namespace stats
}  // namespace power
}  // namespace hardware
}  // namespace android
}  // namespace aidl