#pragma once
#include "block.h"
#include <AL/al.h>
#include <AL/alc.h>

class Audio {
public:
    bool init();      // returns false if OpenAL unavailable (non-fatal)
    void cleanup();

    void playBlockBreak(BlockType bt);
    void playBlockPlace(BlockType bt);
    void playFootstep();
    void playItemPickup();
    void playMobHit();
    void playMobDeath();
    void playUIClick();

private:
    enum Snd {
        SND_BREAK_STONE, SND_BREAK_WOOD, SND_BREAK_SOFT,
        SND_PLACE_STONE,  SND_PLACE_WOOD,  SND_PLACE_SOFT,
        SND_FOOTSTEP, SND_PICKUP,
        SND_MOB_HIT,  SND_MOB_DEATH,
        SND_UI_CLICK,
        SND_COUNT
    };

    static constexpr int NUM_SRC = 16;
    ALCdevice*  dev_  = nullptr;
    ALCcontext* ctx_  = nullptr;
    ALuint bufs_[SND_COUNT]{};
    ALuint srcs_[NUM_SRC]{};
    int    srcIdx_ = 0;

    void generateAll();
    void playBuf(int snd, float gain, float pitch);
};
