#pragma once
#include <string>
#include <vector>
#include <unordered_map>
#include "model/TrackPiece.h"

namespace MC {

class CatalogLoader {
public:
    // Load built-in catalog (no file needed)
    void LoadBuiltIn();

    // Legacy — just calls LoadBuiltIn(), path ignored
    bool Load(const char* path = nullptr);

    const TrackPiece* Find(const std::string& catalogNumber) const;
    const TrackPiece* GetByIndex(int i) const;
    int               Count() const;

    std::vector<const TrackPiece*> GetSeries(TrackSeries series) const;
    std::vector<const TrackPiece*> GetByType(PieceType type) const;

    const std::vector<TrackPiece>& All() const { return m_pieces; }
    bool IsLoaded() const { return m_loaded; }

private:
    std::vector<TrackPiece>                 m_pieces;
    std::unordered_map<std::string, size_t> m_index;
    bool                                    m_loaded = false;
};

CatalogLoader& GetCatalog();

} // namespace MC
