// Code generated by RonyKIT Stub Generator (Golang); DO NOT EDIT.

package sampleservice

import (
	"context"
	"encoding/json"
	"fmt"
	"time"

	"github.com/clubpay/ronykit/kit"
	"github.com/clubpay/ronykit/kit/utils"
	"github.com/clubpay/ronykit/kit/utils/reflector"
	"github.com/clubpay/ronykit/stub"
)

var (
	_ fmt.Stringer
	_ utils.Result
	_ json.RawMessage
	_ time.Time
)

func init() {
	reflector.Register(&ErrorMessage{}, "json")
	reflector.Register(&KeyValue{}, "json")
	reflector.Register(&SimpleHdr{}, "json")
	reflector.Register(&VeryComplexRequest{}, "json")
	reflector.Register(&VeryComplexResponse{}, "json")
}

type IsampleServiceStub interface {
	ComplexDummy(
		ctx context.Context,
		req *VeryComplexRequest,
		opt ...stub.RESTOption,
	) (*VeryComplexResponse, error)

	ComplexDummy2(
		ctx context.Context,
		req *VeryComplexRequest,
		opt ...stub.RESTOption,
	) (*VeryComplexResponse, error)

	GetComplexDummy(
		ctx context.Context,
		req *VeryComplexRequest,
		opt ...stub.RESTOption,
	) (*VeryComplexResponse, error)
}

// ErrorMessage is a data transfer object
type ErrorMessage struct {
	Code int    `json:"code" swag:""`
	Item string `json:"item" swag:""`
}

func (x ErrorMessage) GetCode() int {
	return x.Code
}

func (x ErrorMessage) GetItem() string {
	return x.Item
}

// KeyValue is a data transfer object
type KeyValue struct {
	Key   string `json:"key" swag:""`
	Value int    `json:"value" swag:""`
}

// SimpleHdr is a data transfer object
type SimpleHdr struct {
	Key1 string      `json:"sKey1" swag:""`
	Key2 int         `json:"sKey2" swag:""`
	T1   time.Time   `json:"t1" swag:""`
	T2   *time.Time  `json:"t2" swag:""`
	T3   []time.Time `json:"t3" swag:""`
}

// VeryComplexRequest is a data transfer object
type VeryComplexRequest struct {
	SimpleHdr
	Key1      string             `json:"key1" swag:""`
	Key1Ptr   *string            `json:"key1Ptr" swag:"enum:a,b,c"`
	Key2Ptr   *int               `json:"key2Ptr,omitempty" swag:""`
	MapKey1   map[string]int     `json:"mapKey1" swag:""`
	MapKey2   map[int64]KeyValue `json:"mapKey2" swag:""`
	SliceKey1 []bool             `json:"sliceKey1" swag:""`
	SliceKey2 []*KeyValue        `json:"sliceKey2" swag:""`
	RawKey    kit.JSONMessage    `json:"rawKey" swag:""`
}

type VeryComplexRequest_Key1PtrENUM = string

const (
	VeryComplexRequest_Key1Ptr_A = "a"
	VeryComplexRequest_Key1Ptr_B = "b"
	VeryComplexRequest_Key1Ptr_C = "c"
)

// VeryComplexResponse is a data transfer object
type VeryComplexResponse struct {
	Key1      string              `json:"key1,omitempty" swag:"enum:1,2,3;deprecated"`
	Key1Ptr   *string             `json:"key1Ptr,omitempty" swag:""`
	MapKey1   map[string]int      `json:"mapKey1,omitempty" swag:""`
	MapKey2   map[int64]*KeyValue `json:"mapKey2,omitempty" swag:""`
	SliceKey1 []uint8             `json:"sliceKey1" swag:""`
	SliceKey2 []KeyValue          `json:"sliceKey2" swag:""`
	NoOutput  int                 `json:"-" swag:""`
	Printer   map[string]any      `json:"printer" swag:""`
}

// sampleServiceStub represents the client/stub for sampleService.
// Implements IsampleServiceStub
type sampleServiceStub struct {
	hostPort  string
	secure    bool
	verifyTLS bool

	s *stub.Stub
}

func NewsampleServiceStub(hostPort string, opts ...stub.Option) *sampleServiceStub {
	s := &sampleServiceStub{
		s: stub.New(hostPort, opts...),
	}

	return s
}

var _ IsampleServiceStub = (*sampleServiceStub)(nil)

func (s sampleServiceStub) ComplexDummy(
	ctx context.Context, req *VeryComplexRequest, opt ...stub.RESTOption,
) (*VeryComplexResponse, error) {

	res := &VeryComplexResponse{}

	httpCtx := s.s.REST(opt...).
		SetMethod("POST").
		SetResponseHandler(
			400,
			func(ctx context.Context, r stub.RESTResponse) *stub.Error {
				res := &ErrorMessage{}
				err := stub.WrapError(kit.UnmarshalMessage(r.GetBody(), res))
				if err != nil {
					return err
				}

				return stub.NewErrorWithMsg(res)
			},
		).
		SetOKHandler(
			func(ctx context.Context, r stub.RESTResponse) *stub.Error {

				return stub.WrapError(kit.UnmarshalMessage(r.GetBody(), res))

			},
		).
		DefaultResponseHandler(
			func(ctx context.Context, r stub.RESTResponse) *stub.Error {

				res := &ErrorMessage{}
				err := stub.WrapError(kit.UnmarshalMessage(r.GetBody(), res))
				if err != nil {
					return err
				}

				return stub.NewErrorWithMsg(res)
			},
		).
		AutoRun(ctx, "/complexDummy", kit.CustomEncoding("json"), req)
	defer httpCtx.Release()

	if err := httpCtx.Err(); err != nil {
		return nil, err
	}

	return res, nil
}

func (s sampleServiceStub) ComplexDummy2(
	ctx context.Context, req *VeryComplexRequest, opt ...stub.RESTOption,
) (*VeryComplexResponse, error) {

	res := &VeryComplexResponse{}

	httpCtx := s.s.REST(opt...).
		SetMethod("POST").
		SetResponseHandler(
			400,
			func(ctx context.Context, r stub.RESTResponse) *stub.Error {
				res := &ErrorMessage{}
				err := stub.WrapError(kit.UnmarshalMessage(r.GetBody(), res))
				if err != nil {
					return err
				}

				return stub.NewErrorWithMsg(res)
			},
		).
		SetOKHandler(
			func(ctx context.Context, r stub.RESTResponse) *stub.Error {

				return stub.WrapError(kit.UnmarshalMessage(r.GetBody(), res))

			},
		).
		DefaultResponseHandler(
			func(ctx context.Context, r stub.RESTResponse) *stub.Error {

				res := &ErrorMessage{}
				err := stub.WrapError(kit.UnmarshalMessage(r.GetBody(), res))
				if err != nil {
					return err
				}

				return stub.NewErrorWithMsg(res)
			},
		).
		AutoRun(ctx, "/complexDummy/{key1}", kit.CustomEncoding("json"), req)
	defer httpCtx.Release()

	if err := httpCtx.Err(); err != nil {
		return nil, err
	}

	return res, nil
}

func (s sampleServiceStub) GetComplexDummy(
	ctx context.Context, req *VeryComplexRequest, opt ...stub.RESTOption,
) (*VeryComplexResponse, error) {

	res := &VeryComplexResponse{}

	httpCtx := s.s.REST(opt...).
		SetMethod("GET").
		SetResponseHandler(
			400,
			func(ctx context.Context, r stub.RESTResponse) *stub.Error {
				res := &ErrorMessage{}
				err := stub.WrapError(kit.UnmarshalMessage(r.GetBody(), res))
				if err != nil {
					return err
				}

				return stub.NewErrorWithMsg(res)
			},
		).
		SetOKHandler(
			func(ctx context.Context, r stub.RESTResponse) *stub.Error {

				return stub.WrapError(kit.UnmarshalMessage(r.GetBody(), res))

			},
		).
		DefaultResponseHandler(
			func(ctx context.Context, r stub.RESTResponse) *stub.Error {
				return stub.NewError(r.StatusCode(), string(r.GetBody()))
			},
		).
		AutoRun(ctx, "/complexDummy/{key1}/xs/{sKey1}", kit.CustomEncoding("json"), req)
	defer httpCtx.Release()

	if err := httpCtx.Err(); err != nil {
		return nil, err
	}

	return res, nil
}

type MockOption func(*sampleServiceStubMock)

func MockComplexDummy(
	f func(
		ctx context.Context,
		req *VeryComplexRequest,
		opt ...stub.RESTOption,
	) (*VeryComplexResponse, error),
) MockOption {
	return func(sm *sampleServiceStubMock) {
		sm.complexdummy = f
	}
}

func MockComplexDummy2(
	f func(
		ctx context.Context,
		req *VeryComplexRequest,
		opt ...stub.RESTOption,
	) (*VeryComplexResponse, error),
) MockOption {
	return func(sm *sampleServiceStubMock) {
		sm.complexdummy2 = f
	}
}

func MockGetComplexDummy(
	f func(
		ctx context.Context,
		req *VeryComplexRequest,
		opt ...stub.RESTOption,
	) (*VeryComplexResponse, error),
) MockOption {
	return func(sm *sampleServiceStubMock) {
		sm.getcomplexdummy = f
	}
}

// sampleServiceStubMock represents the mocked for client/stub for sampleService.
// Implements IsampleServiceStub
type sampleServiceStubMock struct {
	complexdummy func(
		ctx context.Context,
		req *VeryComplexRequest,
		opt ...stub.RESTOption,
	) (*VeryComplexResponse, error)

	complexdummy2 func(
		ctx context.Context,
		req *VeryComplexRequest,
		opt ...stub.RESTOption,
	) (*VeryComplexResponse, error)

	getcomplexdummy func(
		ctx context.Context,
		req *VeryComplexRequest,
		opt ...stub.RESTOption,
	) (*VeryComplexResponse, error)
}

func NewsampleServiceStubMock(opts ...MockOption) *sampleServiceStubMock {
	s := &sampleServiceStubMock{}
	for _, o := range opts {
		o(s)
	}

	return s
}

var _ IsampleServiceStub = (*sampleServiceStubMock)(nil)

func (s *sampleServiceStubMock) ComplexDummy(
	ctx context.Context,
	req *VeryComplexRequest,
	opt ...stub.RESTOption,
) (*VeryComplexResponse, error) {
	if s.complexdummy == nil {
		return nil, stub.WrapError(fmt.Errorf("method not mocked"))
	}

	return s.complexdummy(ctx, req, opt...)
}

func (s *sampleServiceStubMock) SetComplexDummy(
	f func(
		ctx context.Context,
		req *VeryComplexRequest,
		opt ...stub.RESTOption,
	) (*VeryComplexResponse, error),
) *sampleServiceStubMock {
	s.complexdummy = f

	return s
}

func (s *sampleServiceStubMock) ComplexDummy2(
	ctx context.Context,
	req *VeryComplexRequest,
	opt ...stub.RESTOption,
) (*VeryComplexResponse, error) {
	if s.complexdummy2 == nil {
		return nil, stub.WrapError(fmt.Errorf("method not mocked"))
	}

	return s.complexdummy2(ctx, req, opt...)
}

func (s *sampleServiceStubMock) SetComplexDummy2(
	f func(
		ctx context.Context,
		req *VeryComplexRequest,
		opt ...stub.RESTOption,
	) (*VeryComplexResponse, error),
) *sampleServiceStubMock {
	s.complexdummy2 = f

	return s
}

func (s *sampleServiceStubMock) GetComplexDummy(
	ctx context.Context,
	req *VeryComplexRequest,
	opt ...stub.RESTOption,
) (*VeryComplexResponse, error) {
	if s.getcomplexdummy == nil {
		return nil, stub.WrapError(fmt.Errorf("method not mocked"))
	}

	return s.getcomplexdummy(ctx, req, opt...)
}

func (s *sampleServiceStubMock) SetGetComplexDummy(
	f func(
		ctx context.Context,
		req *VeryComplexRequest,
		opt ...stub.RESTOption,
	) (*VeryComplexResponse, error),
) *sampleServiceStubMock {
	s.getcomplexdummy = f

	return s
}
