/*
 * Copyright (c) 2026 盐灯水母
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */

package com.remains_cave.dungeon.config;

import org.yaml.snakeyaml.Yaml;
import java.io.InputStream;

public class RoutineConfigLoader {
    public static DungeonRoutineConfig load(String path) {
        String resourcePath = "/" + path;
        try (InputStream is = DungeonRoutineConfig.class.getResourceAsStream(resourcePath)) {
            if (is == null) {
                throw new RuntimeException("Resource not found: " + resourcePath);
            }
            Yaml yaml = new Yaml();
            DungeonRoutineConfig config = yaml.loadAs(is, DungeonRoutineConfig.class);
            if (config == null) {
                throw new RuntimeException("YAML parsing returned null (empty file?)");
            }
            return config;
        } catch (Exception e) {
            throw new RuntimeException("Failed to load dungeon routine config: " + path, e);
        }
    }
}