package node

import (
	"context"
	"fmt"

	"go.uber.org/zap"

	"iop/apps/node/internal/transport"
	iop "iop/proto/gen/iop"
)

// OnCancel cancels one run. Provider processes and logical sessions are not
// part of the Node runtime boundary.
func (n *Node) OnCancel(_ context.Context, _ *transport.Session, req *iop.CancelRequest) error {
	n.logger.Info("cancel request", zap.String("run_id", req.GetRunId()))
	if req.GetRunId() == "" {
		return fmt.Errorf("node: run_id is required for cancellation")
	}
	n.runs.cancelRun(req.GetRunId())
	return nil
}
