using SVSim.BattleNode.Protocol;
using SVSim.BattleNode.Sessions.Participants; // IHasHandshakePhase
namespace SVSim.BattleNode.Sessions.Dispatch;
/// Everything a handler reads or mutates for one inbound frame. /
/// are the session's positional participants (preserved so handlers that iterate participants in a
/// stable order — e.g. the mulligan barrier — match the legacy switch byte-for-byte).
/// is the sender; is the non-sender.
internal sealed class FrameDispatchContext
{
internal required IBattleParticipant A { get; init; }
internal required IBattleParticipant B { get; init; }
internal required IBattleParticipant From { get; init; }
internal required IBattleParticipant Other { get; init; }
internal required MsgEnvelope Env { get; init; }
internal required BattleType Type { get; init; }
internal required string BattleId { get; init; }
internal required BattleSessionState State { get; init; }
/// The dispatching participant's handshake phase (null for a non-IHasHandshakePhase
/// participant, e.g. NoOpBot). Setting it advances the sender.
internal HandshakePhase? SenderPhase
{
get => (From as IHasHandshakePhase)?.Phase;
set { if (From is IHasHandshakePhase p && value is { } v) p.Phase = v; }
}
/// Both participants have completed the handshake. Reads A/B (not From/Other) so the
/// result is identical regardless of which side sent the frame — matches legacy BothAfterReady.
internal bool BothAfterReady() =>
(A as IHasHandshakePhase)?.Phase == HandshakePhase.AfterReady &&
(B as IHasHandshakePhase)?.Phase == HandshakePhase.AfterReady;
}