/*
 * Copyright (c) 2023 Huawei Device Co., Ltd.
 * 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.
 */
#ifndef UPDATER_HARDWARE_FAULT_RETRY_H
#define UPDATER_HARDWARE_FAULT_RETRY_H

#include "log/log.h"
#include <unordered_map>
#include <vector>
#include <sys/time.h>
#include <unistd.h>

namespace Updater {
class HardwareFaultRetry {
public:
    ~HardwareFaultRetry() = default;

    static HardwareFaultRetry &GetInstance();
    using RetryFunc = std::function<void ()>;
    void DoRetryAction();
    void RegisterFunc(const std::string &faultInfo, RetryFunc func);
    void RegisterDefaultFunc(const std::string &faultInfo);
    void RemoveFunc(const std::string &faultInfo);
    void SetFaultInfo(const std::string &faultInfo);
    void SetRetryCount(const uint32_t count);
    void SetEffectiveValue(bool value);
    void SetRebootCmd(const std::string &rebootCmd);
    bool IsRetry(void);

private:
    void RebootRetry();

    std::unordered_map<std::string, RetryFunc> retryMap_ {};
    std::string faultInfo_ {};
    std::string rebootCmd_ {};
    uint32_t retryCount_ {};
    bool effective_ = true;
    bool isRetry_ = false;

private:
    HardwareFaultRetry();
};
} // Updater
#endif // UPDATER_HARDWARE_FAULT_RETRY_H