'use strict';

const path = require('path');
const fs = require('fs');

// monsterSpecs is a single-document namespace (one file, two top-level keys:
// defaults and bySample). It doesn't fit FileBackend's per-id or single-file
// array layouts cleanly — so we inline a tiny loader here instead of bending
// FileBackend to accommodate the shape.
//
// The whole document is exposed under id 'all'. Consumers (AquonSamplesMenu,
// monster specificClass) call assetResolver.resolve('monsterSpecs', 'all').

const FILE_PATH = path.resolve(__dirname, '../../../datasets/assetData/specs/monster/index.json');

function _load() {
    if (!fs.existsSync(FILE_PATH)) return new Map();
    const data = JSON.parse(fs.readFileSync(FILE_PATH, 'utf8'));
    return new Map([['all', {
        defaults: data.defaults || {},
        bySample: data.bySample || {},
    }]]);
}

module.exports = {
    name: 'monsterSpecs',
    description: 'Monster sampling specs (defaults + per-sample overrides) from specs/monster/index.json',
    loadAll: _load,
    refresh: () => _load(),
};
