/*******************************************************************************
 * Copyright (c) 2024-2025 R3944Realms. All rights reserved.
 * <p>
 * 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
 * <p>
 *     http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * 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 com.r3944realms.dg_lab.manager;

import com.r3944realms.dg_lab.utils.unSafe.AtomicClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * DGLab管理接口
 */
public interface IDGLabManager extends com.r3944realms.dg_lab.api.manager.IDGLabManager {
    /**
     * The constant CLIENT_INSTANCE.
     */
    AtomicClass<DGPBClientManager> CLIENT_INSTANCE = new AtomicClass<>(null);
    /**
     * The constant SERVER_INSTANCE.
     */
    AtomicClass<DGPBServerManager> SERVER_INSTANCE = new AtomicClass<>(null);
    /**
     * The constant logger.
     */
    Logger logger = LoggerFactory.getLogger(IDGLabManager.class);

    /**
     * 设置单例客户端管理类
     *
     * @param instance 单例客户端管理类
     */
    static void setClientManagerInstance(DGPBClientManager instance) {
        CLIENT_INSTANCE.set(instance);
    }

    /**
     * 设置单例服务器管理类
     *
     * @param instance 单例服务器管理类
     */
    static void setServerManagerInstance(DGPBServerManager instance) {
        SERVER_INSTANCE.set(instance);
    }

    /**
     * 获取当前单例客户端管理类
     *
     * @return 单例客户端管理类 client manager instance
     */
    static DGPBClientManager getClientManagerInstance() {
        DGPBClientManager dgpbClientManager = CLIENT_INSTANCE.get();
        if (dgpbClientManager == null)
            throw new IllegalStateException("Client manager is not set or is null");
        return dgpbClientManager;
    }

    /**
     * 获取当前单例服务器管理类
     *
     * @return 单例服务器管理类 server manager instance
     */
    static DGPBServerManager getServerManagerInstance() {
        DGPBServerManager dgpbServerManager = SERVER_INSTANCE.get();
        if (dgpbServerManager == null)
            throw new IllegalStateException("Server manager is not set or is null");
        return dgpbServerManager;
    }
}
