/*
 *  Copyright 2025-2026 R3944Realms
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package top.r3944realms.eroticdungeongame.api.workspace;



import org.jetbrains.annotations.ApiStatus;
import top.r3944realms.eroticdungeongame.api.EroticDungeonGameApi;

import java.util.ServiceLoader;

/**
 * The type Services.
 */
@ApiStatus.Internal
public class Services {
    /**
     * The constant WORK_SPACE.
     */
    public static final IWorkSpaceHelper WORK_SPACE = load(IWorkSpaceHelper.class);

    /**
     * Load t.
     *
     * @param <T>   the type parameter
     * @param clazz the clazz
     * @return the t
     */
    public static <T> T load(Class<T> clazz) {
        final T loadedService = ServiceLoader.load(clazz)
                .findFirst()
                .orElseThrow(() -> new NullPointerException("Failed to load service for " + clazz.getName()));
        EroticDungeonGameApi.LOGGER.debug("Loaded {} for service {}", loadedService, clazz);
        return loadedService;
    }
}
