package com.huangzj.cross.cmd;

import com.huangzj.base.cmd.AbstractTypedPbCommand;
import com.huangzj.base.cmd.Cmd;
import com.huangzj.base.cmd.CommandContext;
import com.huangzj.base.cmd.CommandSource;
import com.huangzj.cmd.gen.CrossLinkHeartbeatCts;
import com.huangzj.cmd.gen.CrossLinkHeartbeatStc;
import com.huangzj.cmd.gen.PbService;
import com.huangzj.cmd.gen.Service4_Method;
import org.springframework.stereotype.Component;

/** 区服 ↔ 跨服长连接心跳（仅 {@link CommandSource#CROSS_TCP}）。 */
@Component
@Cmd(
        source = CommandSource.CROSS_TCP,
        serviceId = PbService.Service_4_VALUE,
        methodId = Service4_Method.Heartbeat_VALUE)
public class CrossLinkHeartbeatCommand extends AbstractTypedPbCommand<CrossLinkHeartbeatCts, CrossLinkHeartbeatStc.Builder> {

    @Override
    protected void run(CommandContext ctx, CrossLinkHeartbeatCts cts, CrossLinkHeartbeatStc.Builder stcBuilder) {
        // 原样回显客户端时间，便于区服侧算 RTT；cross_time_ms 为跨服处理时刻
        stcBuilder.setClientTimeMs(cts.getClientTimeMs()).setCrossTimeMs(System.currentTimeMillis());
    }
}
