//go:build !ignore_autogenerated
// +build !ignore_autogenerated

// Code generated by mga tool. DO NOT EDIT.

package pkeservicedriver

import (
	"context"
	"errors"
	cluster "github.com/banzaicloud/pipeline/internal/cluster"
	"github.com/banzaicloud/pipeline/src/api/cluster/pke/pkeservice"
	"github.com/go-kit/kit/endpoint"
	kitxendpoint "github.com/sagikazarmark/kitx/endpoint"
)

// endpointError identifies an error that should be returned as an endpoint error.
type endpointError interface {
	EndpointError() bool
}

// serviceError identifies an error that should be returned as a service error.
type serviceError interface {
	ServiceError() bool
}

// Endpoints collects all of the endpoints that compose the underlying service. It's
// meant to be used as a helper struct, to collect all of the endpoints into a
// single parameter.
type Endpoints struct {
	RegisterNodeStatus endpoint.Endpoint
}

// MakeEndpoints returns a(n) Endpoints struct where each endpoint invokes
// the corresponding method on the provided service.
func MakeEndpoints(service pkeservice.Service, middleware ...endpoint.Middleware) Endpoints {
	mw := kitxendpoint.Combine(middleware...)

	return Endpoints{RegisterNodeStatus: kitxendpoint.OperationNameMiddleware("pkeservice.RegisterNodeStatus")(mw(MakeRegisterNodeStatusEndpoint(service)))}
}

// RegisterNodeStatusRequest is a request struct for RegisterNodeStatus endpoint.
type RegisterNodeStatusRequest struct {
	ClusterIdentifier cluster.Identifier
	NodeStatus        pkeservice.NodeStatus
}

// RegisterNodeStatusResponse is a response struct for RegisterNodeStatus endpoint.
type RegisterNodeStatusResponse struct {
	Resp pkeservice.RegisterNodeStatusResponse
	Err  error
}

func (r RegisterNodeStatusResponse) Failed() error {
	return r.Err
}

// MakeRegisterNodeStatusEndpoint returns an endpoint for the matching method of the underlying service.
func MakeRegisterNodeStatusEndpoint(service pkeservice.Service) endpoint.Endpoint {
	return func(ctx context.Context, request interface{}) (interface{}, error) {
		req := request.(RegisterNodeStatusRequest)

		resp, err := service.RegisterNodeStatus(ctx, req.ClusterIdentifier, req.NodeStatus)

		if err != nil {
			if serviceErr := serviceError(nil); errors.As(err, &serviceErr) && serviceErr.ServiceError() {
				return RegisterNodeStatusResponse{
					Err:  err,
					Resp: resp,
				}, nil
			}

			return RegisterNodeStatusResponse{
				Err:  err,
				Resp: resp,
			}, err
		}

		return RegisterNodeStatusResponse{Resp: resp}, nil
	}
}
