/* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
 * -*- coding: utf-8 -*-
 *
 * Copyright (C) 2025 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef VOLUMECONTROL_H
#define VOLUMECONTROL_H

#include "BackendFactory.h"
#include "BaseType.h"
#include "PulseaudioBackendFactory.h"
#include "PipewireBackendFactory.h"
#include "ManagerFactory.h"
#include "PulseaudioManagerFactory.h"
#include "PipewireManagerFactory.h"
#include "AudioManager.h"
#include "AudioContext.h"
#include "AudioMethod.h"

namespace UkuiAudioFramwork
{
class VolumeControl
{
public:
    static VolumeControl& getInstance();

public:
    void init();

private:
    VolumeControl() = default;
    VolumeControl(const VolumeControl&) = delete;
    VolumeControl(VolumeControl&&) = delete;
    VolumeControl operator=(const VolumeControl&) = delete;
    VolumeControl operator=(VolumeControl&&) = delete;
    virtual ~VolumeControl() = default;

private:
    BackendType m_type = BackendType::PULSEAUDIO;
    std::shared_ptr<BackendFactory> m_pBackendFactory;
    std::shared_ptr<IBackend> m_pBackend;
    std::shared_ptr<ManagerFactory> m_pManagerFactory;
    std::shared_ptr<AudioManager> m_pAudioManager;

    std::unordered_map<ModuleType, std::vector<std::string>> m_settingsMap = {
        {ModuleType::MODULE_REMAP_SINK, {MONO_AUDIO_KEY, "module-remap-sink", "sink_name=mono channels=1 channel_map=mono"}},
        {ModuleType::MODULE_ECHO_CANCEL, {NOISE_REDUCTION_KEY, "module-echo-cancel", "use_master_format=1 aec_method=webrtc aec_args=analog_gain_control=0 source_name=noiseReduceSource"}},
        {ModuleType::MODULE_LOOPBACK ,{LOOPBACK_KEY, "module-loopback", ""}}
    };

    std::unordered_map<std::string, std::function<bool()>> m_statusFunctions = {
        {MONO_AUDIO_KEY, [this]() { return AudioMethod::getInstance().getMonoStatus(); }},
        {NOISE_REDUCTION_KEY, [this]() { return AudioMethod::getInstance().getEchoCancelStatus(); }},
        {LOOPBACK_KEY, [this]() { return AudioMethod::getInstance().getLoopbackStatus(); }}
    };
};
}
#endif // VOLUMECONTROL_H
