// Code generated by protoc-gen-micro. DO NOT EDIT.
// source: proto/cache.proto

package cache

import (
	fmt "fmt"
	proto "google.golang.org/protobuf/proto"
	math "math"
)

import (
	context "context"
	api "go-micro.dev/v4/api"
	client "go-micro.dev/v4/client"
	server "go-micro.dev/v4/server"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf

// Reference imports to suppress errors if they are not otherwise used.
var _ api.Endpoint
var _ context.Context
var _ client.Option
var _ server.Option

// Api Endpoints for Cache service

func NewCacheEndpoints() []*api.Endpoint {
	return []*api.Endpoint{}
}

// Client API for Cache service

type CacheService interface {
	// Get receives a value and its time to live by key from the cache.
	Get(ctx context.Context, in *GetRequest, opts ...client.CallOption) (*GetResponse, error)
	// Put stores a value and its time to live in the cache.
	Put(ctx context.Context, in *PutRequest, opts ...client.CallOption) (*PutResponse, error)
	// Delete removes a key from the cache.
	Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error)
}

type cacheService struct {
	c    client.Client
	name string
}

func NewCacheService(name string, c client.Client) CacheService {
	return &cacheService{
		c:    c,
		name: name,
	}
}

func (c *cacheService) Get(ctx context.Context, in *GetRequest, opts ...client.CallOption) (*GetResponse, error) {
	req := c.c.NewRequest(c.name, "Cache.Get", in)
	out := new(GetResponse)
	err := c.c.Call(ctx, req, out, opts...)
	if err != nil {
		return nil, err
	}
	return out, nil
}

func (c *cacheService) Put(ctx context.Context, in *PutRequest, opts ...client.CallOption) (*PutResponse, error) {
	req := c.c.NewRequest(c.name, "Cache.Put", in)
	out := new(PutResponse)
	err := c.c.Call(ctx, req, out, opts...)
	if err != nil {
		return nil, err
	}
	return out, nil
}

func (c *cacheService) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) {
	req := c.c.NewRequest(c.name, "Cache.Delete", in)
	out := new(DeleteResponse)
	err := c.c.Call(ctx, req, out, opts...)
	if err != nil {
		return nil, err
	}
	return out, nil
}

// Server API for Cache service

type CacheHandler interface {
	// Get receives a value and its time to live by key from the cache.
	Get(context.Context, *GetRequest, *GetResponse) error
	// Put stores a value and its time to live in the cache.
	Put(context.Context, *PutRequest, *PutResponse) error
	// Delete removes a key from the cache.
	Delete(context.Context, *DeleteRequest, *DeleteResponse) error
}

func RegisterCacheHandler(s server.Server, hdlr CacheHandler, opts ...server.HandlerOption) error {
	type cache interface {
		Get(ctx context.Context, in *GetRequest, out *GetResponse) error
		Put(ctx context.Context, in *PutRequest, out *PutResponse) error
		Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error
	}
	type Cache struct {
		cache
	}
	h := &cacheHandler{hdlr}
	return s.Handle(s.NewHandler(&Cache{h}, opts...))
}

type cacheHandler struct {
	CacheHandler
}

func (h *cacheHandler) Get(ctx context.Context, in *GetRequest, out *GetResponse) error {
	return h.CacheHandler.Get(ctx, in, out)
}

func (h *cacheHandler) Put(ctx context.Context, in *PutRequest, out *PutResponse) error {
	return h.CacheHandler.Put(ctx, in, out)
}

func (h *cacheHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error {
	return h.CacheHandler.Delete(ctx, in, out)
}
