package pb

import (
	"context"

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

type RegisterRequest struct {
	ServerId    string `json:"server_id"`
	PreRegToken string `json:"pre_reg_token"`
	Hostname    string `json:"hostname"`
	IpAddress   string `json:"ip_address"`
	OsInfo      string `json:"os_info"`
}

type RegisterResponse struct {
	AgentToken string `json:"agent_token"`
}

type SyncRequest struct {
	ServerId     string `json:"server_id"`
	AgentToken   string `json:"agent_token"`
	AgentVersion string `json:"agent_version,omitempty"`
}

type SyncResponse struct {
	PublicKeys []string `json:"public_keys"`
	// CollectPackages tells the agent whether this instance's licence grants
	// vulnerability scanning. Absent decodes as false, which is the safe
	// direction: an older server leaves agents collecting nothing.
	CollectPackages bool `json:"collect_packages,omitempty"`
}

type OSRelease struct {
	Family string `json:"family"`
	// VersionId is not optional: Ubuntu 22.04 and 24.04 publish different fixed
	// versions for the same CVE, so a scan without it is guesswork.
	VersionId string `json:"version_id"`
	Arch      string `json:"arch,omitempty"`
}

type InstalledPackage struct {
	Name    string `json:"name"`
	Version string `json:"version"`
	Epoch   int32  `json:"epoch,omitempty"`
	Arch    string `json:"arch,omitempty"`
	// SourceName is what the Debian and Ubuntu feeds are keyed on: one advisory
	// against "openssl" covers libssl3, openssl and libssl-dev.
	SourceName string `json:"source_name,omitempty"`
}

// ReportPackagesRequest carries a server's installed package set.
//
// The agent calls twice at most: first with Packages empty, offering only the
// hash. If the server already holds it, NeedFull is false and the ~150KB body
// is never sent.
type ReportPackagesRequest struct {
	ServerId   string             `json:"server_id"`
	AgentToken string             `json:"agent_token"`
	Hash       string             `json:"hash"`
	Os         OSRelease          `json:"os"`
	Packages   []InstalledPackage `json:"packages,omitempty"`
}

type ReportPackagesResponse struct {
	NeedFull bool `json:"need_full"`
}

type UploadKeyRequest struct {
	ServerId   string `json:"server_id"`
	AgentToken string `json:"agent_token"`
	PublicKey  string `json:"public_key"`
	Label      string `json:"label"`
	PrivateKey string `json:"private_key,omitempty"`
}

type UploadKeyResponse struct {
	KeyId string `json:"key_id"`
}

type PackageUpdate struct {
	Name           string `json:"name"`
	CurrentVersion string `json:"current_version,omitempty"`
	NewVersion     string `json:"new_version"`
}

type ReportUpdatesRequest struct {
	ServerId   string          `json:"server_id"`
	AgentToken string          `json:"agent_token"`
	Updates    []PackageUpdate `json:"updates"`
}

type ReportUpdatesResponse struct{}

type CPUReport struct {
	Model    string  `json:"model,omitempty"`
	Cores    int     `json:"cores,omitempty"`
	UsagePct float64 `json:"usage_pct"`
	Load1    float64 `json:"load1,omitempty"`
}
type MemReport struct {
	TotalBytes uint64 `json:"total_bytes"`
	UsedBytes  uint64 `json:"used_bytes"`
}
type PartitionReport struct {
	Device     string `json:"device"`
	Mountpoint string `json:"mountpoint"`
	Fstype     string `json:"fstype,omitempty"`
	TotalBytes uint64 `json:"total_bytes"`
	UsedBytes  uint64 `json:"used_bytes"`
}
type InventoryReport struct {
	ServerId      string            `json:"server_id"`
	AgentToken    string            `json:"agent_token"`
	IncludeStatic bool              `json:"include_static"`
	CPU           *CPUReport        `json:"cpu,omitempty"`
	Memory        *MemReport        `json:"memory,omitempty"`
	SwapTotal     uint64            `json:"swap_total"`
	SwapUsed      uint64            `json:"swap_used"`
	Partitions    []PartitionReport `json:"partitions,omitempty"`
	Kernel        string            `json:"kernel,omitempty"`
}
type InventoryReportResponse struct{}

type MonitorSpec struct {
	MonitorId      string `json:"monitor_id"`
	Type           string `json:"type"`
	URL            string `json:"url,omitempty"`
	Host           string `json:"host,omitempty"`
	Port           int    `json:"port,omitempty"`
	Method         string `json:"method,omitempty"`
	ExpectedStatus int    `json:"expected_status,omitempty"`
	Keyword        string `json:"keyword,omitempty"`
	TLSWarnDays    int    `json:"tls_warn_days,omitempty"`
	Insecure       bool   `json:"insecure,omitempty"`
	IntervalSec    int    `json:"interval_sec"`
	Retries        int    `json:"retries"`
}
type SyncMonitorsRequest struct {
	ServerId   string `json:"server_id"`
	AgentToken string `json:"agent_token"`
}
type SyncMonitorsResponse struct {
	Monitors []MonitorSpec `json:"monitors,omitempty"`
}
type CheckResult struct {
	MonitorId      string `json:"monitor_id"`
	Up             bool   `json:"up"`
	LatencyMs      int    `json:"latency_ms"`
	Message        string `json:"message,omitempty"`
	CertExpiryUnix int64  `json:"cert_expiry_unix,omitempty"`
}
type ReportChecksRequest struct {
	ServerId   string        `json:"server_id"`
	AgentToken string        `json:"agent_token"`
	Results    []CheckResult `json:"results,omitempty"`
}
type ReportChecksResponse struct{}

type ApplyUpdatesCmd struct{}

type OpenProxyCmd struct {
	ProxyId string `json:"proxy_id"`
	Port    uint32 `json:"port"`
}

type ProxyOpen struct {
	ServerId   string `json:"server_id"`
	AgentToken string `json:"agent_token"`
	ProxyId    string `json:"proxy_id"`
}

type ProxyClose struct {
	Reason string `json:"reason,omitempty"`
}

type ProxyClientMsg struct {
	Open  *ProxyOpen  `json:"open,omitempty"`
	Data  []byte      `json:"data,omitempty"`
	Close *ProxyClose `json:"close,omitempty"`
}

type ProxyServerMsg struct {
	Data  []byte      `json:"data,omitempty"`
	Close *ProxyClose `json:"close,omitempty"`
}

type ServerCommand struct {
	CommandId        string               `json:"command_id"`
	GenerateKey      *GenerateKeyCmd      `json:"generate_key,omitempty"`
	DeleteKey        *DeleteKeyCmd        `json:"delete_key,omitempty"`
	UpdateAgent      *UpdateAgentCmd      `json:"update_agent,omitempty"`
	ApplyUpdates     *ApplyUpdatesCmd     `json:"apply_updates,omitempty"`
	RunStep          *RunStepCmd          `json:"run_step,omitempty"`
	CleanupWorkspace *CleanupWorkspaceCmd `json:"cleanup_workspace,omitempty"`
	OpenProxy        *OpenProxyCmd        `json:"open_proxy,omitempty"`
	Ping             *PingCmd             `json:"ping,omitempty"`

	RefreshWorkloads *RefreshWorkloadsCmd `json:"refresh_workloads,omitempty"`
	ControlWorkload  *ControlWorkloadCmd  `json:"control_workload,omitempty"`
	WorkloadLogs     *WorkloadLogsCmd     `json:"workload_logs,omitempty"`
}

// PingCmd is a server-originated liveness beat. It carries nothing and expects
// no reply: its arrival is the entire message. See the .proto for why gRPC
// keepalive is not sufficient on its own.
type PingCmd struct{}

type CleanupWorkspaceCmd struct {
	WorkspaceId string `json:"workspace_id"`
}

type DeleteKeyCmd struct {
	Label string `json:"label"`
}

type UpdateAgentCmd struct {
	Version      string `json:"version"`
	GiteaBaseURL string `json:"gitea_base_url"`
}

type GenerateKeyCmd struct {
	Label      string `json:"label"`
	KeyType    string `json:"key_type,omitempty"`
	KeySize    int    `json:"key_size,omitempty"`
	Passphrase string `json:"passphrase,omitempty"`
	Comment    string `json:"comment,omitempty"`
}

type AgentMessage struct {
	ServerId   string           `json:"server_id"`
	AgentToken string           `json:"agent_token"`
	Ready      *AgentReady      `json:"ready,omitempty"`
	Result     *CommandResult   `json:"result,omitempty"`
	StepResult *StepResult      `json:"step_result,omitempty"`
	StepOutput *StepOutputChunk `json:"step_output,omitempty"`

	WorkloadLogsResult *WorkloadLogsResult `json:"workload_logs_result,omitempty"`
}

type AgentReady struct{}

type CommandResult struct {
	CommandId string `json:"command_id"`
	Success   bool   `json:"success"`
	Message   string `json:"message"`
}

type RunStepCmd struct {
	Interpreter    string            `json:"interpreter"`
	Script         string            `json:"script"`
	Env            map[string]string `json:"env,omitempty"`
	TimeoutSeconds int               `json:"timeout_seconds,omitempty"`

	WorkspaceId string `json:"workspace_id,omitempty"`
}

type StepResult struct {
	CommandId string            `json:"command_id"`
	ExitCode  int               `json:"exit_code"`
	Stdout    string            `json:"stdout,omitempty"`
	Stderr    string            `json:"stderr,omitempty"`
	OutputEnv map[string]string `json:"output_env,omitempty"`
}

type StepOutputChunk struct {
	CommandId string `json:"command_id"`
	Seq       uint64 `json:"seq"`
	Data      []byte `json:"data,omitempty"`
	Eof       bool   `json:"eof,omitempty"`
}

type Vantage_CommandStreamServer interface {
	Send(*ServerCommand) error
	Recv() (*AgentMessage, error)
	grpc.ServerStream
}

type keyManagerCommandStreamServer struct {
	grpc.ServerStream
}

func (s *keyManagerCommandStreamServer) Send(m *ServerCommand) error {
	return s.ServerStream.SendMsg(m)
}

func (s *keyManagerCommandStreamServer) Recv() (*AgentMessage, error) {
	m := new(AgentMessage)
	if err := s.ServerStream.RecvMsg(m); err != nil {
		return nil, err
	}
	return m, nil
}

type Vantage_CommandStreamClient interface {
	Send(*AgentMessage) error
	Recv() (*ServerCommand, error)
	grpc.ClientStream
}

type vantageCommandStreamClient struct {
	grpc.ClientStream
}

func (c *vantageCommandStreamClient) Send(m *AgentMessage) error {
	return c.ClientStream.SendMsg(m)
}

func (c *vantageCommandStreamClient) Recv() (*ServerCommand, error) {
	m := new(ServerCommand)
	if err := c.ClientStream.RecvMsg(m); err != nil {
		return nil, err
	}
	return m, nil
}

type Vantage_ProxyStreamServer interface {
	Send(*ProxyServerMsg) error
	Recv() (*ProxyClientMsg, error)
	grpc.ServerStream
}

type vantageProxyStreamServer struct {
	grpc.ServerStream
}

func (s *vantageProxyStreamServer) Send(m *ProxyServerMsg) error {
	return s.ServerStream.SendMsg(m)
}

func (s *vantageProxyStreamServer) Recv() (*ProxyClientMsg, error) {
	m := new(ProxyClientMsg)
	if err := s.ServerStream.RecvMsg(m); err != nil {
		return nil, err
	}
	return m, nil
}

type Vantage_ProxyStreamClient interface {
	Send(*ProxyClientMsg) error
	Recv() (*ProxyServerMsg, error)
	CloseSend() error
	grpc.ClientStream
}

type vantageProxyStreamClient struct {
	grpc.ClientStream
}

func (c *vantageProxyStreamClient) Send(m *ProxyClientMsg) error {
	return c.ClientStream.SendMsg(m)
}

func (c *vantageProxyStreamClient) Recv() (*ProxyServerMsg, error) {
	m := new(ProxyServerMsg)
	if err := c.ClientStream.RecvMsg(m); err != nil {
		return nil, err
	}
	return m, nil
}

func _Vantage_ProxyStream_Handler(srv interface{}, stream grpc.ServerStream) error {
	return srv.(VantageServer).ProxyStream(&vantageProxyStreamServer{stream})
}

type VantageServer interface {
	Register(context.Context, *RegisterRequest) (*RegisterResponse, error)
	SyncKeys(context.Context, *SyncRequest) (*SyncResponse, error)
	UploadGeneratedKey(context.Context, *UploadKeyRequest) (*UploadKeyResponse, error)
	ReportUpdates(context.Context, *ReportUpdatesRequest) (*ReportUpdatesResponse, error)
	ReportPackages(context.Context, *ReportPackagesRequest) (*ReportPackagesResponse, error)
	ReportWorkloads(context.Context, *ReportWorkloadsRequest) (*ReportWorkloadsResponse, error)
	ReportInventory(context.Context, *InventoryReport) (*InventoryReportResponse, error)
	SyncMonitors(context.Context, *SyncMonitorsRequest) (*SyncMonitorsResponse, error)
	ReportChecks(context.Context, *ReportChecksRequest) (*ReportChecksResponse, error)
	CommandStream(Vantage_CommandStreamServer) error
	ProxyStream(Vantage_ProxyStreamServer) error
}

type UnimplementedVantageServer struct{}

func (UnimplementedVantageServer) Register(context.Context, *RegisterRequest) (*RegisterResponse, error) {
	return nil, status.Errorf(codes.Unimplemented, "method Register not implemented")
}

func (UnimplementedVantageServer) SyncKeys(context.Context, *SyncRequest) (*SyncResponse, error) {
	return nil, status.Errorf(codes.Unimplemented, "method SyncKeys not implemented")
}

func (UnimplementedVantageServer) UploadGeneratedKey(context.Context, *UploadKeyRequest) (*UploadKeyResponse, error) {
	return nil, status.Errorf(codes.Unimplemented, "method UploadGeneratedKey not implemented")
}

func (UnimplementedVantageServer) ReportUpdates(context.Context, *ReportUpdatesRequest) (*ReportUpdatesResponse, error) {
	return nil, status.Errorf(codes.Unimplemented, "method ReportUpdates not implemented")
}

func (UnimplementedVantageServer) ReportPackages(context.Context, *ReportPackagesRequest) (*ReportPackagesResponse, error) {
	return nil, status.Errorf(codes.Unimplemented, "method ReportPackages not implemented")
}

func (UnimplementedVantageServer) ReportInventory(context.Context, *InventoryReport) (*InventoryReportResponse, error) {
	return nil, status.Errorf(codes.Unimplemented, "method ReportInventory not implemented")
}

func (UnimplementedVantageServer) SyncMonitors(context.Context, *SyncMonitorsRequest) (*SyncMonitorsResponse, error) {
	return nil, status.Errorf(codes.Unimplemented, "method SyncMonitors not implemented")
}

func (UnimplementedVantageServer) ReportChecks(context.Context, *ReportChecksRequest) (*ReportChecksResponse, error) {
	return nil, status.Errorf(codes.Unimplemented, "method ReportChecks not implemented")
}

func (UnimplementedVantageServer) CommandStream(Vantage_CommandStreamServer) error {
	return status.Errorf(codes.Unimplemented, "method CommandStream not implemented")
}

func (UnimplementedVantageServer) ProxyStream(Vantage_ProxyStreamServer) error {
	return status.Errorf(codes.Unimplemented, "method ProxyStream not implemented")
}

type VantageClient interface {
	Register(ctx context.Context, in *RegisterRequest, opts ...grpc.CallOption) (*RegisterResponse, error)
	SyncKeys(ctx context.Context, in *SyncRequest, opts ...grpc.CallOption) (*SyncResponse, error)
	UploadGeneratedKey(ctx context.Context, in *UploadKeyRequest, opts ...grpc.CallOption) (*UploadKeyResponse, error)
	ReportUpdates(ctx context.Context, in *ReportUpdatesRequest, opts ...grpc.CallOption) (*ReportUpdatesResponse, error)
	ReportPackages(ctx context.Context, in *ReportPackagesRequest, opts ...grpc.CallOption) (*ReportPackagesResponse, error)
	ReportWorkloads(ctx context.Context, in *ReportWorkloadsRequest, opts ...grpc.CallOption) (*ReportWorkloadsResponse, error)
	ReportInventory(ctx context.Context, in *InventoryReport, opts ...grpc.CallOption) (*InventoryReportResponse, error)
	SyncMonitors(ctx context.Context, in *SyncMonitorsRequest, opts ...grpc.CallOption) (*SyncMonitorsResponse, error)
	ReportChecks(ctx context.Context, in *ReportChecksRequest, opts ...grpc.CallOption) (*ReportChecksResponse, error)
	CommandStream(ctx context.Context, opts ...grpc.CallOption) (Vantage_CommandStreamClient, error)
	ProxyStream(ctx context.Context, opts ...grpc.CallOption) (Vantage_ProxyStreamClient, error)
}

type keyManagerClient struct {
	cc grpc.ClientConnInterface
}

func NewVantageClient(cc grpc.ClientConnInterface) VantageClient {
	return &keyManagerClient{cc}
}

func (c *keyManagerClient) Register(ctx context.Context, in *RegisterRequest, opts ...grpc.CallOption) (*RegisterResponse, error) {
	out := new(RegisterResponse)
	if err := c.cc.Invoke(ctx, "/vantage.v1.Vantage/Register", in, out, opts...); err != nil {
		return nil, err
	}
	return out, nil
}

func (c *keyManagerClient) SyncKeys(ctx context.Context, in *SyncRequest, opts ...grpc.CallOption) (*SyncResponse, error) {
	out := new(SyncResponse)
	if err := c.cc.Invoke(ctx, "/vantage.v1.Vantage/SyncKeys", in, out, opts...); err != nil {
		return nil, err
	}
	return out, nil
}

func (c *keyManagerClient) UploadGeneratedKey(ctx context.Context, in *UploadKeyRequest, opts ...grpc.CallOption) (*UploadKeyResponse, error) {
	out := new(UploadKeyResponse)
	if err := c.cc.Invoke(ctx, "/vantage.v1.Vantage/UploadGeneratedKey", in, out, opts...); err != nil {
		return nil, err
	}
	return out, nil
}

func (c *keyManagerClient) ReportUpdates(ctx context.Context, in *ReportUpdatesRequest, opts ...grpc.CallOption) (*ReportUpdatesResponse, error) {
	out := new(ReportUpdatesResponse)
	if err := c.cc.Invoke(ctx, "/vantage.v1.Vantage/ReportUpdates", in, out, opts...); err != nil {
		return nil, err
	}
	return out, nil
}

func (c *keyManagerClient) ReportPackages(ctx context.Context, in *ReportPackagesRequest, opts ...grpc.CallOption) (*ReportPackagesResponse, error) {
	out := new(ReportPackagesResponse)
	if err := c.cc.Invoke(ctx, "/vantage.v1.Vantage/ReportPackages", in, out, opts...); err != nil {
		return nil, err
	}
	return out, nil
}

func (c *keyManagerClient) ReportInventory(ctx context.Context, in *InventoryReport, opts ...grpc.CallOption) (*InventoryReportResponse, error) {
	out := new(InventoryReportResponse)
	if err := c.cc.Invoke(ctx, "/vantage.v1.Vantage/ReportInventory", in, out, opts...); err != nil {
		return nil, err
	}
	return out, nil
}

func (c *keyManagerClient) SyncMonitors(ctx context.Context, in *SyncMonitorsRequest, opts ...grpc.CallOption) (*SyncMonitorsResponse, error) {
	out := new(SyncMonitorsResponse)
	if err := c.cc.Invoke(ctx, "/vantage.v1.Vantage/SyncMonitors", in, out, opts...); err != nil {
		return nil, err
	}
	return out, nil
}

func (c *keyManagerClient) ReportChecks(ctx context.Context, in *ReportChecksRequest, opts ...grpc.CallOption) (*ReportChecksResponse, error) {
	out := new(ReportChecksResponse)
	if err := c.cc.Invoke(ctx, "/vantage.v1.Vantage/ReportChecks", in, out, opts...); err != nil {
		return nil, err
	}
	return out, nil
}

func (c *keyManagerClient) CommandStream(ctx context.Context, opts ...grpc.CallOption) (Vantage_CommandStreamClient, error) {
	stream, err := c.cc.NewStream(ctx, &Vantage_ServiceDesc.Streams[0], "/vantage.v1.Vantage/CommandStream", opts...)
	if err != nil {
		return nil, err
	}
	return &vantageCommandStreamClient{stream}, nil
}

func (c *keyManagerClient) ProxyStream(ctx context.Context, opts ...grpc.CallOption) (Vantage_ProxyStreamClient, error) {
	stream, err := c.cc.NewStream(ctx, &Vantage_ServiceDesc.Streams[1], "/vantage.v1.Vantage/ProxyStream", opts...)
	if err != nil {
		return nil, err
	}
	return &vantageProxyStreamClient{stream}, nil
}

func RegisterVantageServer(s grpc.ServiceRegistrar, srv VantageServer) {
	s.RegisterService(&Vantage_ServiceDesc, srv)
}

var Vantage_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "vantage.v1.Vantage",
	HandlerType: (*VantageServer)(nil),
	Methods: []grpc.MethodDesc{
		{MethodName: "Register", Handler: _Vantage_Register_Handler},
		{MethodName: "SyncKeys", Handler: _Vantage_SyncKeys_Handler},
		{MethodName: "UploadGeneratedKey", Handler: _Vantage_UploadGeneratedKey_Handler},
		{MethodName: "ReportUpdates", Handler: _Vantage_ReportUpdates_Handler},
		{MethodName: "ReportPackages", Handler: _Vantage_ReportPackages_Handler},
		{MethodName: "ReportWorkloads", Handler: _Vantage_ReportWorkloads_Handler},
		{MethodName: "ReportInventory", Handler: _Vantage_ReportInventory_Handler},
		{MethodName: "SyncMonitors", Handler: _Vantage_SyncMonitors_Handler},
		{MethodName: "ReportChecks", Handler: _Vantage_ReportChecks_Handler},
	},
	Streams: []grpc.StreamDesc{
		{
			StreamName:    "CommandStream",
			Handler:       _Vantage_CommandStream_Handler,
			ServerStreams: true,
			ClientStreams: true,
		},
		{
			StreamName:    "ProxyStream",
			Handler:       _Vantage_ProxyStream_Handler,
			ServerStreams: true,
			ClientStreams: true,
		},
	},
	Metadata: "vantage/v1/vantage.proto",
}

func _Vantage_Register_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
	in := new(RegisterRequest)
	if err := dec(in); err != nil {
		return nil, err
	}
	if interceptor == nil {
		return srv.(VantageServer).Register(ctx, in)
	}
	info := &grpc.UnaryServerInfo{Server: srv, FullMethod: "/vantage.v1.Vantage/Register"}
	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
		return srv.(VantageServer).Register(ctx, req.(*RegisterRequest))
	}
	return interceptor(ctx, in, info, handler)
}

func _Vantage_SyncKeys_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
	in := new(SyncRequest)
	if err := dec(in); err != nil {
		return nil, err
	}
	if interceptor == nil {
		return srv.(VantageServer).SyncKeys(ctx, in)
	}
	info := &grpc.UnaryServerInfo{Server: srv, FullMethod: "/vantage.v1.Vantage/SyncKeys"}
	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
		return srv.(VantageServer).SyncKeys(ctx, req.(*SyncRequest))
	}
	return interceptor(ctx, in, info, handler)
}

func _Vantage_UploadGeneratedKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
	in := new(UploadKeyRequest)
	if err := dec(in); err != nil {
		return nil, err
	}
	if interceptor == nil {
		return srv.(VantageServer).UploadGeneratedKey(ctx, in)
	}
	info := &grpc.UnaryServerInfo{Server: srv, FullMethod: "/vantage.v1.Vantage/UploadGeneratedKey"}
	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
		return srv.(VantageServer).UploadGeneratedKey(ctx, req.(*UploadKeyRequest))
	}
	return interceptor(ctx, in, info, handler)
}

func _Vantage_ReportUpdates_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
	in := new(ReportUpdatesRequest)
	if err := dec(in); err != nil {
		return nil, err
	}
	if interceptor == nil {
		return srv.(VantageServer).ReportUpdates(ctx, in)
	}
	info := &grpc.UnaryServerInfo{Server: srv, FullMethod: "/vantage.v1.Vantage/ReportUpdates"}
	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
		return srv.(VantageServer).ReportUpdates(ctx, req.(*ReportUpdatesRequest))
	}
	return interceptor(ctx, in, info, handler)
}

func _Vantage_ReportPackages_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
	in := new(ReportPackagesRequest)
	if err := dec(in); err != nil {
		return nil, err
	}
	if interceptor == nil {
		return srv.(VantageServer).ReportPackages(ctx, in)
	}
	info := &grpc.UnaryServerInfo{Server: srv, FullMethod: "/vantage.v1.Vantage/ReportPackages"}
	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
		return srv.(VantageServer).ReportPackages(ctx, req.(*ReportPackagesRequest))
	}
	return interceptor(ctx, in, info, handler)
}

func _Vantage_ReportInventory_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
	in := new(InventoryReport)
	if err := dec(in); err != nil {
		return nil, err
	}
	if interceptor == nil {
		return srv.(VantageServer).ReportInventory(ctx, in)
	}
	info := &grpc.UnaryServerInfo{Server: srv, FullMethod: "/vantage.v1.Vantage/ReportInventory"}
	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
		return srv.(VantageServer).ReportInventory(ctx, req.(*InventoryReport))
	}
	return interceptor(ctx, in, info, handler)
}

func _Vantage_SyncMonitors_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
	in := new(SyncMonitorsRequest)
	if err := dec(in); err != nil {
		return nil, err
	}
	if interceptor == nil {
		return srv.(VantageServer).SyncMonitors(ctx, in)
	}
	info := &grpc.UnaryServerInfo{Server: srv, FullMethod: "/vantage.v1.Vantage/SyncMonitors"}
	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
		return srv.(VantageServer).SyncMonitors(ctx, req.(*SyncMonitorsRequest))
	}
	return interceptor(ctx, in, info, handler)
}

func _Vantage_ReportChecks_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
	in := new(ReportChecksRequest)
	if err := dec(in); err != nil {
		return nil, err
	}
	if interceptor == nil {
		return srv.(VantageServer).ReportChecks(ctx, in)
	}
	info := &grpc.UnaryServerInfo{Server: srv, FullMethod: "/vantage.v1.Vantage/ReportChecks"}
	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
		return srv.(VantageServer).ReportChecks(ctx, req.(*ReportChecksRequest))
	}
	return interceptor(ctx, in, info, handler)
}

func _Vantage_CommandStream_Handler(srv interface{}, stream grpc.ServerStream) error {
	return srv.(VantageServer).CommandStream(&keyManagerCommandStreamServer{stream})
}
