//
//  AudioBus.hpp
//  SwitchboardSDK
//
//  Created by Balázs Kiss on 2022. 03. 19..
//  Copyright © 2022. Synervoz Inc. All rights reserved.
//

#pragma once

#include "AudioBuffer.hpp"
#include "AudioBusFormat.hpp"
#include <switchboard/export.h>

namespace switchboard {

/**
 * AudioBus class.
 * @brief Represents a stream of audio in one direction.
 * @details Multiple audio buses can be handled together by the AudioBusList class.
 */
struct SWITCHBOARDSDK_EXPORT AudioBus {
    /**
     * @brief The audio buffer that contains the audio data.
     * @deprecated Please use getBuffer() and setBuffer() methods instead.
     */
    AudioBuffer<float>* buffer = nullptr;

    /**
     * @brief Default audioBus constructor.
     */
    AudioBus() = default;

    /**
     *  @brief AudioBus constructor.
     *
     *  @param buffer The audio buffer containing audio data.
     */
    AudioBus(AudioBuffer<float>* buffer);

    /**
     * @brief Gets the format of the audio bus.
     *
     * @returns The AudioBusFormat instance describing the format of the audio bus.
     */
    [[nodiscard]] AudioBusFormat getFormat() const;

    /**
     * @brief Sets the format of the audio bus.
     *
     * @param newFormat The new AudioBusFormat to be set.
     */
    void setFormat(const AudioBusFormat& newFormat);

    /**
     * @brief Gets the audio buffer of the audio bus.
     *
     * @returns The audio buffer object.
     */
    AudioBuffer<float>* getBuffer() const;

    /**
     * @brief Sets the audio buffer of the audio bus.
     *
     * @param newBuffer The new audio buffer to be set.
     */
    void setBuffer(AudioBuffer<float>* newBuffer);

    /**
     * @brief Checks if the audio bus is connected to another audio bus.
     *
     * @returns True if the audio bus is connected, false otherwise.
     */
    [[nodiscard]] bool isConnected() const;

    /**
     * @brief Copies another AudioBus instance.
     */
    void copyFrom(const AudioBus& srcAudioBus);

    /**
     * @brief Sets the content of the audio bus to zero.
     */
    void clear();

private:
    AudioBusFormat format;
};

}
