/**
 * Copyright (C) 2013 Canonical, Ltd.
 * Copyright (C) 2025-2026 Andres Salomon <dilinger@queued.net>
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License version 3, as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef OFONOPHONESIMHELPER_H
#define OFONOPHONESIMHELPER_H

#include <QObject>

#include <ofonomodem.h>
#include <ofonocallvolume.h>
#include <ofonomessagemanager.h>
#include <ofonovoicecallmanager.h>
#include <ofonovoicecall.h>
#include <ofononetworkregistration.h>
#include <ofonosimmanager.h>
#include <ofonocellbroadcast.h>

class OfonoPhonesimHelper : public QObject
{
    Q_OBJECT
public:
    static OfonoPhonesimHelper *instance();

    bool NetworkRegistrationSetStatus(const QString &status);
    bool MessageManagerSendMessage(const QString &from, const QString &text);
    void MessageManagerUseDeliveryReports(bool val);
    void CellBroadcastPower(bool powered);
    bool CellBroadcastCMASNotification(const QString &text, quint16 channel);
    bool CellBroadcastETWSNotification(const QString &text, const QString &type, bool alert, bool popup);
    bool VoiceCallManagerIncomingCall(const QString &from);
    void VoiceCallManagerSwapCalls();
    bool VoiceCallHangup(const QString &objPath);
//    void VoiceCallManagerFailNextDtmf();
    bool VoiceCallAnswer(const QString &objPath);
    bool VoiceCallSetAlerting(const QString &objPath);
    void ModemSetOnline(bool online);
    bool ModemIsValid() const;
    bool IsPresent() const;
    const QString SimManagerGetPinRequired() const;
    const QString NetworkRegistrationStatus() const;
    const QString NetworkRegistrationGetName() const;

Q_SIGNALS:
    void CellBroadcastPoweredUp();
    void MessageAdded(const QString &message);
    void DeliveryReportsChanged(bool val);
    void CallAdded(const QString &call, const QVariantMap &values);
    void MutedChanged(bool muted);
    void VoiceCallChanged(const QString &state);
    void SwapCallsComplete(bool status, const QString &errName, const QString &errMsg);

private Q_SLOTS:
    void onCallAdded(const QString &call, const QVariantMap &values);
    void onCallRemoved(const QString &call);
    void onCBPowerChanged(bool powered);
    void onInterfacesChanged(const QStringList &interfaces);

private:
    int findCall(const QString &call);
    bool ExecJS(const QString &dir, const QString &script);
    bool RunJavascript(const QString &js);

    explicit OfonoPhonesimHelper(QObject *parent = 0);
    OfonoNetworkRegistration *mNetworkRegistration;
    OfonoMessageManager *mMessageManager;
    OfonoVoiceCallManager *mVoiceCallManager;
    QList<OfonoVoiceCall*> mVoiceCalls;
    OfonoSimManager *mSimManager;
    OfonoCellBroadcast *mCellBroadcast;
    OfonoCallVolume *mCallVolume;
    OfonoModem *mModem;
    const QString mModemName;
    const OfonoModem::SelectionSetting mSetting;
    QString mJsDir;
};

#endif // OFONOPHONESIMHELPER_H
