/*
 * Copyright (c) 2026 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 PCM_FILE_READER_H
#define PCM_FILE_READER_H

#include <fstream>
#include <string>
#include <cstdint>
#include "AudioConfig.h"
#include "AudioLog.h"

class PCMFileReader {
public:
    PCMFileReader();
    ~PCMFileReader();

    int32_t Open(const std::string &filePath, int32_t sampleRate, int32_t channelCount, int32_t bitsPerSample);
    int32_t Read(uint8_t *buffer, int32_t bytesToRead);
    void Close();
    void Reset();
    int64_t GetFileSize() const
    {
        return fileSize_;
    }
    int64_t GetCurrentPosition() const
    {
        return currentPosition_;
    }

    int32_t GetSampleRate() const
    {
        return sampleRate_;
    }
    int32_t GetChannelCount() const
    {
        return channelCount_;
    }
    int32_t GetBitsPerSample() const
    {
        return bitsPerSample_;
    }
    int32_t GetBytesPerSample() const
    {
        return bytesPerSample_;
    }
    int32_t GetFrameSize() const
    {
        return frameSize_;
    }

    bool IsEOF() const;
    bool IsOpen() const
    {
        return file_.is_open();
    }

private:
    std::ifstream file_;
    std::string filePath_;
    int32_t sampleRate_ = 48000;
    int32_t channelCount_ = 2;
    int32_t bitsPerSample_ = 24;
    int32_t bytesPerSample_ = 3;
    int32_t frameSize_ = 6;
    int64_t fileSize_ = 0;
    int64_t currentPosition_ = 0;
};

#endif