// Copyright 2026 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
//
// Licensing note: while most of forgejo/runner is distributed under the terms
// of GPL-3.0-or-later, this plugin definition file is more permissively
// licensed under the MIT license.  This choice allows plugin authors to embed
// it, create derived works of it (e.g. generated source files), and
// distribute derived products under a wider variety of licenses.

// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.6.2
// - protoc             (unknown)
// source: act/plugin/proto/v1alpha/plugin.proto

package pluginv1alpha

import (
	context "context"

	grpc "google.golang.org/grpc"
	codes "google.golang.org/grpc/codes"
	status "google.golang.org/grpc/status"
)

// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9

const (
	BackendPlugin_Capabilities_FullMethodName = "/plugin.v1alpha.BackendPlugin/Capabilities"
	BackendPlugin_Create_FullMethodName       = "/plugin.v1alpha.BackendPlugin/Create"
	BackendPlugin_Start_FullMethodName        = "/plugin.v1alpha.BackendPlugin/Start"
	BackendPlugin_Exec_FullMethodName         = "/plugin.v1alpha.BackendPlugin/Exec"
	BackendPlugin_CopyIn_FullMethodName       = "/plugin.v1alpha.BackendPlugin/CopyIn"
	BackendPlugin_CopyOut_FullMethodName      = "/plugin.v1alpha.BackendPlugin/CopyOut"
	BackendPlugin_Remove_FullMethodName       = "/plugin.v1alpha.BackendPlugin/Remove"
)

// BackendPluginClient is the client API for BackendPlugin service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
//
// BackendPlugin is the gRPC service a plugin server implements to run jobs in an
// execution environment it owns (a Kubernetes pod, a VM, ...). The runner
// connects to a standalone plugin server and drives the environment lifecycle
// through it. Plugin servers must also expose the standard grpc.health.v1
// service.
//
// For any given environment ID, the runner will not invoke a new RPC while
// a previous RPS for that environment is outstanding, with one exception:
// for streaming RPCs, the runner closes or cancels the stream and may
// immediately invoke a subsequent RPC (typically `Remove`). As teardown of
// a cancelled stream is not instantaneous, implementations may observe a
// subsequent RPC invoked while a previous streaming RPC's handler is still
// executing internally. This behaviour is expected. Exclusive locking of each
// environment during each RPC is recommended for most implementations to
// accomodate this, ensuring that a `Remove` operation and the last in-flight
// RPC operation (currently being cancelled) do not cause internal errors.
//
// This is an alpha protocol: it may change in incompatible ways between
// releases. Errors are reported with gRPC status codes; the runner relies on
// NotFound (unknown environment_id) and InvalidArgument (malformed request),
// and treats Unavailable as the plugin being gone. The status message is shown
// in the job log; no structured error details are defined yet.
type BackendPluginClient interface {
	// Capabilities returns the backend's identity, filesystem layout, and the one
	// feature flag the runner needs. Called once at connection time.
	Capabilities(ctx context.Context, in *CapabilitiesRequest, opts ...grpc.CallOption) (*CapabilitiesResponse, error)
	// Create provisions a new execution environment. Service containers are
	// passed here so the backend realises them however fits its platform.
	Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error)
	// Start boots a previously created environment.
	//
	// Start implementations should detect when the RPC stream is terminated
	// externally before the command completes, as this will signal explicit job
	// cancellation, or job timeout. When detected, the implementation should
	// terminate the startup process on the environment. The Remove RPC for the
	// environment will follow, even though the Start RPC did not complete.
	Start(ctx context.Context, in *StartRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[StartOutput], error)
	// Exec runs a command inside the environment, streaming stdout/stderr back.
	//
	// Exec implementations should detect when the RPC stream is terminated
	// externally before the command completes, as this will signal explicit job
	// cancellation, job timeout, or command timeout. When detected, the
	// implementation should terminate the running command on the
	// environment. Implementation should not rely on a failed write to the
	// output stream as its cancellation signal as some commands produce
	// infrequent output. (Implementation note: observing context cancellation in
	// Go, a cancellation-aware select on the response channel in Rust's
	// `tokio::sync::mspc::Sender::closed()`, or a server-side cancellation
	// callback in Python/Java.)
	Exec(ctx context.Context, in *ExecRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[ExecOutput], error)
	// CopyIn transfers a tar archive into the environment.
	CopyIn(ctx context.Context, opts ...grpc.CallOption) (grpc.ClientStreamingClient[CopyInChunk, CopyInResponse], error)
	// CopyOut transfers a tar archive out of the environment. The runner reads
	// env files (GITHUB_ENV/OUTPUT/STATE) back this way and parses them itself.
	CopyOut(ctx context.Context, in *CopyOutRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[CopyOutChunk], error)
	// Remove tears down the environment and releases its resources.
	Remove(ctx context.Context, in *RemoveRequest, opts ...grpc.CallOption) (*RemoveResponse, error)
}

type backendPluginClient struct {
	cc grpc.ClientConnInterface
}

func NewBackendPluginClient(cc grpc.ClientConnInterface) BackendPluginClient {
	return &backendPluginClient{cc}
}

func (c *backendPluginClient) Capabilities(ctx context.Context, in *CapabilitiesRequest, opts ...grpc.CallOption) (*CapabilitiesResponse, error) {
	cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
	out := new(CapabilitiesResponse)
	err := c.cc.Invoke(ctx, BackendPlugin_Capabilities_FullMethodName, in, out, cOpts...)
	if err != nil {
		return nil, err
	}
	return out, nil
}

func (c *backendPluginClient) Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) {
	cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
	out := new(CreateResponse)
	err := c.cc.Invoke(ctx, BackendPlugin_Create_FullMethodName, in, out, cOpts...)
	if err != nil {
		return nil, err
	}
	return out, nil
}

func (c *backendPluginClient) Start(ctx context.Context, in *StartRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[StartOutput], error) {
	cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
	stream, err := c.cc.NewStream(ctx, &BackendPlugin_ServiceDesc.Streams[0], BackendPlugin_Start_FullMethodName, cOpts...)
	if err != nil {
		return nil, err
	}
	x := &grpc.GenericClientStream[StartRequest, StartOutput]{ClientStream: stream}
	if err := x.ClientStream.SendMsg(in); err != nil {
		return nil, err
	}
	if err := x.ClientStream.CloseSend(); err != nil {
		return nil, err
	}
	return x, nil
}

// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type BackendPlugin_StartClient = grpc.ServerStreamingClient[StartOutput]

func (c *backendPluginClient) Exec(ctx context.Context, in *ExecRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[ExecOutput], error) {
	cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
	stream, err := c.cc.NewStream(ctx, &BackendPlugin_ServiceDesc.Streams[1], BackendPlugin_Exec_FullMethodName, cOpts...)
	if err != nil {
		return nil, err
	}
	x := &grpc.GenericClientStream[ExecRequest, ExecOutput]{ClientStream: stream}
	if err := x.ClientStream.SendMsg(in); err != nil {
		return nil, err
	}
	if err := x.ClientStream.CloseSend(); err != nil {
		return nil, err
	}
	return x, nil
}

// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type BackendPlugin_ExecClient = grpc.ServerStreamingClient[ExecOutput]

func (c *backendPluginClient) CopyIn(ctx context.Context, opts ...grpc.CallOption) (grpc.ClientStreamingClient[CopyInChunk, CopyInResponse], error) {
	cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
	stream, err := c.cc.NewStream(ctx, &BackendPlugin_ServiceDesc.Streams[2], BackendPlugin_CopyIn_FullMethodName, cOpts...)
	if err != nil {
		return nil, err
	}
	x := &grpc.GenericClientStream[CopyInChunk, CopyInResponse]{ClientStream: stream}
	return x, nil
}

// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type BackendPlugin_CopyInClient = grpc.ClientStreamingClient[CopyInChunk, CopyInResponse]

func (c *backendPluginClient) CopyOut(ctx context.Context, in *CopyOutRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[CopyOutChunk], error) {
	cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
	stream, err := c.cc.NewStream(ctx, &BackendPlugin_ServiceDesc.Streams[3], BackendPlugin_CopyOut_FullMethodName, cOpts...)
	if err != nil {
		return nil, err
	}
	x := &grpc.GenericClientStream[CopyOutRequest, CopyOutChunk]{ClientStream: stream}
	if err := x.ClientStream.SendMsg(in); err != nil {
		return nil, err
	}
	if err := x.ClientStream.CloseSend(); err != nil {
		return nil, err
	}
	return x, nil
}

// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type BackendPlugin_CopyOutClient = grpc.ServerStreamingClient[CopyOutChunk]

func (c *backendPluginClient) Remove(ctx context.Context, in *RemoveRequest, opts ...grpc.CallOption) (*RemoveResponse, error) {
	cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
	out := new(RemoveResponse)
	err := c.cc.Invoke(ctx, BackendPlugin_Remove_FullMethodName, in, out, cOpts...)
	if err != nil {
		return nil, err
	}
	return out, nil
}

// BackendPluginServer is the server API for BackendPlugin service.
// All implementations must embed UnimplementedBackendPluginServer
// for forward compatibility.
//
// BackendPlugin is the gRPC service a plugin server implements to run jobs in an
// execution environment it owns (a Kubernetes pod, a VM, ...). The runner
// connects to a standalone plugin server and drives the environment lifecycle
// through it. Plugin servers must also expose the standard grpc.health.v1
// service.
//
// For any given environment ID, the runner will not invoke a new RPC while
// a previous RPS for that environment is outstanding, with one exception:
// for streaming RPCs, the runner closes or cancels the stream and may
// immediately invoke a subsequent RPC (typically `Remove`). As teardown of
// a cancelled stream is not instantaneous, implementations may observe a
// subsequent RPC invoked while a previous streaming RPC's handler is still
// executing internally. This behaviour is expected. Exclusive locking of each
// environment during each RPC is recommended for most implementations to
// accomodate this, ensuring that a `Remove` operation and the last in-flight
// RPC operation (currently being cancelled) do not cause internal errors.
//
// This is an alpha protocol: it may change in incompatible ways between
// releases. Errors are reported with gRPC status codes; the runner relies on
// NotFound (unknown environment_id) and InvalidArgument (malformed request),
// and treats Unavailable as the plugin being gone. The status message is shown
// in the job log; no structured error details are defined yet.
type BackendPluginServer interface {
	// Capabilities returns the backend's identity, filesystem layout, and the one
	// feature flag the runner needs. Called once at connection time.
	Capabilities(context.Context, *CapabilitiesRequest) (*CapabilitiesResponse, error)
	// Create provisions a new execution environment. Service containers are
	// passed here so the backend realises them however fits its platform.
	Create(context.Context, *CreateRequest) (*CreateResponse, error)
	// Start boots a previously created environment.
	//
	// Start implementations should detect when the RPC stream is terminated
	// externally before the command completes, as this will signal explicit job
	// cancellation, or job timeout. When detected, the implementation should
	// terminate the startup process on the environment. The Remove RPC for the
	// environment will follow, even though the Start RPC did not complete.
	Start(*StartRequest, grpc.ServerStreamingServer[StartOutput]) error
	// Exec runs a command inside the environment, streaming stdout/stderr back.
	//
	// Exec implementations should detect when the RPC stream is terminated
	// externally before the command completes, as this will signal explicit job
	// cancellation, job timeout, or command timeout. When detected, the
	// implementation should terminate the running command on the
	// environment. Implementation should not rely on a failed write to the
	// output stream as its cancellation signal as some commands produce
	// infrequent output. (Implementation note: observing context cancellation in
	// Go, a cancellation-aware select on the response channel in Rust's
	// `tokio::sync::mspc::Sender::closed()`, or a server-side cancellation
	// callback in Python/Java.)
	Exec(*ExecRequest, grpc.ServerStreamingServer[ExecOutput]) error
	// CopyIn transfers a tar archive into the environment.
	CopyIn(grpc.ClientStreamingServer[CopyInChunk, CopyInResponse]) error
	// CopyOut transfers a tar archive out of the environment. The runner reads
	// env files (GITHUB_ENV/OUTPUT/STATE) back this way and parses them itself.
	CopyOut(*CopyOutRequest, grpc.ServerStreamingServer[CopyOutChunk]) error
	// Remove tears down the environment and releases its resources.
	Remove(context.Context, *RemoveRequest) (*RemoveResponse, error)
	mustEmbedUnimplementedBackendPluginServer()
}

// UnimplementedBackendPluginServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedBackendPluginServer struct{}

func (UnimplementedBackendPluginServer) Capabilities(context.Context, *CapabilitiesRequest) (*CapabilitiesResponse, error) {
	return nil, status.Error(codes.Unimplemented, "method Capabilities not implemented")
}

func (UnimplementedBackendPluginServer) Create(context.Context, *CreateRequest) (*CreateResponse, error) {
	return nil, status.Error(codes.Unimplemented, "method Create not implemented")
}

func (UnimplementedBackendPluginServer) Start(*StartRequest, grpc.ServerStreamingServer[StartOutput]) error {
	return status.Error(codes.Unimplemented, "method Start not implemented")
}

func (UnimplementedBackendPluginServer) Exec(*ExecRequest, grpc.ServerStreamingServer[ExecOutput]) error {
	return status.Error(codes.Unimplemented, "method Exec not implemented")
}

func (UnimplementedBackendPluginServer) CopyIn(grpc.ClientStreamingServer[CopyInChunk, CopyInResponse]) error {
	return status.Error(codes.Unimplemented, "method CopyIn not implemented")
}

func (UnimplementedBackendPluginServer) CopyOut(*CopyOutRequest, grpc.ServerStreamingServer[CopyOutChunk]) error {
	return status.Error(codes.Unimplemented, "method CopyOut not implemented")
}

func (UnimplementedBackendPluginServer) Remove(context.Context, *RemoveRequest) (*RemoveResponse, error) {
	return nil, status.Error(codes.Unimplemented, "method Remove not implemented")
}
func (UnimplementedBackendPluginServer) mustEmbedUnimplementedBackendPluginServer() {}
func (UnimplementedBackendPluginServer) testEmbeddedByValue()                       {}

// UnsafeBackendPluginServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to BackendPluginServer will
// result in compilation errors.
type UnsafeBackendPluginServer interface {
	mustEmbedUnimplementedBackendPluginServer()
}

func RegisterBackendPluginServer(s grpc.ServiceRegistrar, srv BackendPluginServer) {
	// If the following call panics, it indicates UnimplementedBackendPluginServer was
	// embedded by pointer and is nil.  This will cause panics if an
	// unimplemented method is ever invoked, so we test this at initialization
	// time to prevent it from happening at runtime later due to I/O.
	if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
		t.testEmbeddedByValue()
	}
	s.RegisterService(&BackendPlugin_ServiceDesc, srv)
}

func _BackendPlugin_Capabilities_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
	in := new(CapabilitiesRequest)
	if err := dec(in); err != nil {
		return nil, err
	}
	if interceptor == nil {
		return srv.(BackendPluginServer).Capabilities(ctx, in)
	}
	info := &grpc.UnaryServerInfo{
		Server:     srv,
		FullMethod: BackendPlugin_Capabilities_FullMethodName,
	}
	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
		return srv.(BackendPluginServer).Capabilities(ctx, req.(*CapabilitiesRequest))
	}
	return interceptor(ctx, in, info, handler)
}

func _BackendPlugin_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
	in := new(CreateRequest)
	if err := dec(in); err != nil {
		return nil, err
	}
	if interceptor == nil {
		return srv.(BackendPluginServer).Create(ctx, in)
	}
	info := &grpc.UnaryServerInfo{
		Server:     srv,
		FullMethod: BackendPlugin_Create_FullMethodName,
	}
	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
		return srv.(BackendPluginServer).Create(ctx, req.(*CreateRequest))
	}
	return interceptor(ctx, in, info, handler)
}

func _BackendPlugin_Start_Handler(srv interface{}, stream grpc.ServerStream) error {
	m := new(StartRequest)
	if err := stream.RecvMsg(m); err != nil {
		return err
	}
	return srv.(BackendPluginServer).Start(m, &grpc.GenericServerStream[StartRequest, StartOutput]{ServerStream: stream})
}

// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type BackendPlugin_StartServer = grpc.ServerStreamingServer[StartOutput]

func _BackendPlugin_Exec_Handler(srv interface{}, stream grpc.ServerStream) error {
	m := new(ExecRequest)
	if err := stream.RecvMsg(m); err != nil {
		return err
	}
	return srv.(BackendPluginServer).Exec(m, &grpc.GenericServerStream[ExecRequest, ExecOutput]{ServerStream: stream})
}

// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type BackendPlugin_ExecServer = grpc.ServerStreamingServer[ExecOutput]

func _BackendPlugin_CopyIn_Handler(srv interface{}, stream grpc.ServerStream) error {
	return srv.(BackendPluginServer).CopyIn(&grpc.GenericServerStream[CopyInChunk, CopyInResponse]{ServerStream: stream})
}

// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type BackendPlugin_CopyInServer = grpc.ClientStreamingServer[CopyInChunk, CopyInResponse]

func _BackendPlugin_CopyOut_Handler(srv interface{}, stream grpc.ServerStream) error {
	m := new(CopyOutRequest)
	if err := stream.RecvMsg(m); err != nil {
		return err
	}
	return srv.(BackendPluginServer).CopyOut(m, &grpc.GenericServerStream[CopyOutRequest, CopyOutChunk]{ServerStream: stream})
}

// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type BackendPlugin_CopyOutServer = grpc.ServerStreamingServer[CopyOutChunk]

func _BackendPlugin_Remove_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
	in := new(RemoveRequest)
	if err := dec(in); err != nil {
		return nil, err
	}
	if interceptor == nil {
		return srv.(BackendPluginServer).Remove(ctx, in)
	}
	info := &grpc.UnaryServerInfo{
		Server:     srv,
		FullMethod: BackendPlugin_Remove_FullMethodName,
	}
	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
		return srv.(BackendPluginServer).Remove(ctx, req.(*RemoveRequest))
	}
	return interceptor(ctx, in, info, handler)
}

// BackendPlugin_ServiceDesc is the grpc.ServiceDesc for BackendPlugin service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var BackendPlugin_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "plugin.v1alpha.BackendPlugin",
	HandlerType: (*BackendPluginServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "Capabilities",
			Handler:    _BackendPlugin_Capabilities_Handler,
		},
		{
			MethodName: "Create",
			Handler:    _BackendPlugin_Create_Handler,
		},
		{
			MethodName: "Remove",
			Handler:    _BackendPlugin_Remove_Handler,
		},
	},
	Streams: []grpc.StreamDesc{
		{
			StreamName:    "Start",
			Handler:       _BackendPlugin_Start_Handler,
			ServerStreams: true,
		},
		{
			StreamName:    "Exec",
			Handler:       _BackendPlugin_Exec_Handler,
			ServerStreams: true,
		},
		{
			StreamName:    "CopyIn",
			Handler:       _BackendPlugin_CopyIn_Handler,
			ClientStreams: true,
		},
		{
			StreamName:    "CopyOut",
			Handler:       _BackendPlugin_CopyOut_Handler,
			ServerStreams: true,
		},
	},
	Metadata: "act/plugin/proto/v1alpha/plugin.proto",
}
