/*******************************************************************************
 * 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.websocket.handler;

import com.r3944realms.dg_lab.api.operation.IOperation;
import com.r3944realms.dg_lab.api.websocket.message.role.Role;
import com.r3944realms.dg_lab.api.websocket.sharedData.ISharedData;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * The type Abstract dg lab power box handler context wrapper.
 */
public abstract class AbstractDgLabPowerBoxHandlerContextWrapper {
    /**
     * The constant logger.
     */
    public static final Logger logger = LoggerFactory.getLogger(AbstractDgLabPowerBoxHandlerContextWrapper.class);

    /**
     * The Shared data.
     */
    protected final ISharedData sharedData;
    /**
     * The Operation.
     */
    protected final IOperation operation;
    /**
     * The Role.
     */
    protected final Role role;

    /**
     * Gets role.
     *
     * @return the role
     */
    public Role getRole() {
        return role;
    }

    /**
     * Gets shared data.
     *
     * @return the shared data
     */
    public ISharedData getSharedData() {
        return sharedData.clone();
    }

    /**
     * Gets operation.
     *
     * @return the operation
     */
    public IOperation getOperation() {
        return operation;
    }

    /**
     * Instantiates a new Abstract dg lab power box handler context wrapper.
     *
     * @param sharedData the shared data
     * @param role       the role
     * @param operation  the operation
     */
    public AbstractDgLabPowerBoxHandlerContextWrapper(
            ISharedData sharedData,
            Role role,
            IOperation operation
    ) {
        this.sharedData = sharedData;
        this.operation = operation;
        this.role = role;
    }

    /**
     * 连接建立时触发
     *
     * @param session {@link ChannelHandlerContext Context}
     */
    public abstract void SessionBuildInHandle(ChannelHandlerContext session);

    /**
     * 连接存活时触发
     *
     * @param session {@link ChannelHandlerContext Context}
     */
    public abstract void ActiveSessionHandle(ChannelHandlerContext session);

    /**
     * 连接关闭时触发
     *
     * @param session {@link ChannelHandlerContext Context}
     */
    public abstract void SessionCloseHandle(ChannelHandlerContext session);

    /**
     * 连接获取信息时触发
     *
     * @param session {@link ChannelHandlerContext Context}
     * @param frame   {@link TextWebSocketFrame frame}
     */
    public abstract void ReadMsgHandle(ChannelHandlerContext session, TextWebSocketFrame frame);

    /**
     * 连接出现错误时触发
     *
     * @param session {@link ChannelHandlerContext Context}
     * @param cause   {@link Throwable cause}
     */
    public abstract void ErrorHandler(ChannelHandlerContext session, Throwable cause);

}
