// Code generated by gtrace. DO NOT EDIT.

package gtrace

import (
	"context"

	"github.com/ydb-platform/ydb-go-sdk/v3/trace"
)

// schemeComposeOptions is a holder of options
type schemeComposeOptions struct {
	panicCallback func(e interface{})
}

// SchemeOption specified Scheme compose option
// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals
type SchemeComposeOption func(o *schemeComposeOptions)

// WithSchemePanicCallback specified behavior on panic
// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals
func WithSchemePanicCallback(cb func(e interface{})) SchemeComposeOption {
	return func(o *schemeComposeOptions) {
		o.panicCallback = cb
	}
}

// Compose returns a new Scheme which has functional fields composed both from lhs and rhs.
// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals
func Compose(lhs *trace.Scheme, rhs *trace.Scheme, opts ...SchemeComposeOption) *trace.Scheme {
	if lhs == nil {
		return rhs
	}
	var ret trace.Scheme
	options := schemeComposeOptions{}
	for _, opt := range opts {
		if opt != nil {
			opt(&options)
		}
	}
	{
		h1 := lhs.OnListDirectory
		h2 := rhs.OnListDirectory
		ret.OnListDirectory = func(s trace.SchemeListDirectoryStartInfo) func(trace.SchemeListDirectoryDoneInfo) {
			if options.panicCallback != nil {
				defer func() {
					if e := recover(); e != nil {
						options.panicCallback(e)
					}
				}()
			}
			var r, r1 func(trace.SchemeListDirectoryDoneInfo)
			if h1 != nil {
				r = h1(s)
			}
			if h2 != nil {
				r1 = h2(s)
			}
			return func(s trace.SchemeListDirectoryDoneInfo) {
				if options.panicCallback != nil {
					defer func() {
						if e := recover(); e != nil {
							options.panicCallback(e)
						}
					}()
				}
				if r != nil {
					r(s)
				}
				if r1 != nil {
					r1(s)
				}
			}
		}
	}
	{
		h1 := lhs.OnDescribePath
		h2 := rhs.OnDescribePath
		ret.OnDescribePath = func(s trace.SchemeDescribePathStartInfo) func(trace.SchemeDescribePathDoneInfo) {
			if options.panicCallback != nil {
				defer func() {
					if e := recover(); e != nil {
						options.panicCallback(e)
					}
				}()
			}
			var r, r1 func(trace.SchemeDescribePathDoneInfo)
			if h1 != nil {
				r = h1(s)
			}
			if h2 != nil {
				r1 = h2(s)
			}
			return func(s trace.SchemeDescribePathDoneInfo) {
				if options.panicCallback != nil {
					defer func() {
						if e := recover(); e != nil {
							options.panicCallback(e)
						}
					}()
				}
				if r != nil {
					r(s)
				}
				if r1 != nil {
					r1(s)
				}
			}
		}
	}
	{
		h1 := lhs.OnMakeDirectory
		h2 := rhs.OnMakeDirectory
		ret.OnMakeDirectory = func(s trace.SchemeMakeDirectoryStartInfo) func(trace.SchemeMakeDirectoryDoneInfo) {
			if options.panicCallback != nil {
				defer func() {
					if e := recover(); e != nil {
						options.panicCallback(e)
					}
				}()
			}
			var r, r1 func(trace.SchemeMakeDirectoryDoneInfo)
			if h1 != nil {
				r = h1(s)
			}
			if h2 != nil {
				r1 = h2(s)
			}
			return func(s trace.SchemeMakeDirectoryDoneInfo) {
				if options.panicCallback != nil {
					defer func() {
						if e := recover(); e != nil {
							options.panicCallback(e)
						}
					}()
				}
				if r != nil {
					r(s)
				}
				if r1 != nil {
					r1(s)
				}
			}
		}
	}
	{
		h1 := lhs.OnRemoveDirectory
		h2 := rhs.OnRemoveDirectory
		ret.OnRemoveDirectory = func(s trace.SchemeRemoveDirectoryStartInfo) func(trace.SchemeRemoveDirectoryDoneInfo) {
			if options.panicCallback != nil {
				defer func() {
					if e := recover(); e != nil {
						options.panicCallback(e)
					}
				}()
			}
			var r, r1 func(trace.SchemeRemoveDirectoryDoneInfo)
			if h1 != nil {
				r = h1(s)
			}
			if h2 != nil {
				r1 = h2(s)
			}
			return func(s trace.SchemeRemoveDirectoryDoneInfo) {
				if options.panicCallback != nil {
					defer func() {
						if e := recover(); e != nil {
							options.panicCallback(e)
						}
					}()
				}
				if r != nil {
					r(s)
				}
				if r1 != nil {
					r1(s)
				}
			}
		}
	}
	{
		h1 := lhs.OnModifyPermissions
		h2 := rhs.OnModifyPermissions
		ret.OnModifyPermissions = func(s trace.SchemeModifyPermissionsStartInfo) func(trace.SchemeModifyPermissionsDoneInfo) {
			if options.panicCallback != nil {
				defer func() {
					if e := recover(); e != nil {
						options.panicCallback(e)
					}
				}()
			}
			var r, r1 func(trace.SchemeModifyPermissionsDoneInfo)
			if h1 != nil {
				r = h1(s)
			}
			if h2 != nil {
				r1 = h2(s)
			}
			return func(s trace.SchemeModifyPermissionsDoneInfo) {
				if options.panicCallback != nil {
					defer func() {
						if e := recover(); e != nil {
							options.panicCallback(e)
						}
					}()
				}
				if r != nil {
					r(s)
				}
				if r1 != nil {
					r1(s)
				}
			}
		}
	}
	return &ret
}
func onListDirectory(t *trace.Scheme, s trace.SchemeListDirectoryStartInfo) func(trace.SchemeListDirectoryDoneInfo) {
	fn := t.OnListDirectory
	if fn == nil {
		return func(trace.SchemeListDirectoryDoneInfo) {
			return
		}
	}
	res := fn(s)
	if res == nil {
		return func(trace.SchemeListDirectoryDoneInfo) {
			return
		}
	}
	return res
}
func onDescribePath(t *trace.Scheme, s trace.SchemeDescribePathStartInfo) func(trace.SchemeDescribePathDoneInfo) {
	fn := t.OnDescribePath
	if fn == nil {
		return func(trace.SchemeDescribePathDoneInfo) {
			return
		}
	}
	res := fn(s)
	if res == nil {
		return func(trace.SchemeDescribePathDoneInfo) {
			return
		}
	}
	return res
}
func onMakeDirectory(t *trace.Scheme, s trace.SchemeMakeDirectoryStartInfo) func(trace.SchemeMakeDirectoryDoneInfo) {
	fn := t.OnMakeDirectory
	if fn == nil {
		return func(trace.SchemeMakeDirectoryDoneInfo) {
			return
		}
	}
	res := fn(s)
	if res == nil {
		return func(trace.SchemeMakeDirectoryDoneInfo) {
			return
		}
	}
	return res
}
func onRemoveDirectory(t *trace.Scheme, s trace.SchemeRemoveDirectoryStartInfo) func(trace.SchemeRemoveDirectoryDoneInfo) {
	fn := t.OnRemoveDirectory
	if fn == nil {
		return func(trace.SchemeRemoveDirectoryDoneInfo) {
			return
		}
	}
	res := fn(s)
	if res == nil {
		return func(trace.SchemeRemoveDirectoryDoneInfo) {
			return
		}
	}
	return res
}
func onModifyPermissions(t *trace.Scheme, s trace.SchemeModifyPermissionsStartInfo) func(trace.SchemeModifyPermissionsDoneInfo) {
	fn := t.OnModifyPermissions
	if fn == nil {
		return func(trace.SchemeModifyPermissionsDoneInfo) {
			return
		}
	}
	res := fn(s)
	if res == nil {
		return func(trace.SchemeModifyPermissionsDoneInfo) {
			return
		}
	}
	return res
}
// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals
func SchemeOnListDirectory(t *trace.Scheme, c *context.Context, c1 trace.Call) func(error) {
	var p trace.SchemeListDirectoryStartInfo
	p.Context = c
	p.Call = c1
	res := onListDirectory(t, p)
	return func(e error) {
		var p trace.SchemeListDirectoryDoneInfo
		p.Error = e
		res(p)
	}
}
// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals
func SchemeOnDescribePath(t *trace.Scheme, c *context.Context, c1 trace.Call, path string) func(entryType string, _ error) {
	var p trace.SchemeDescribePathStartInfo
	p.Context = c
	p.Call = c1
	p.Path = path
	res := onDescribePath(t, p)
	return func(entryType string, e error) {
		var p trace.SchemeDescribePathDoneInfo
		p.EntryType = entryType
		p.Error = e
		res(p)
	}
}
// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals
func SchemeOnMakeDirectory(t *trace.Scheme, c *context.Context, c1 trace.Call, path string) func(error) {
	var p trace.SchemeMakeDirectoryStartInfo
	p.Context = c
	p.Call = c1
	p.Path = path
	res := onMakeDirectory(t, p)
	return func(e error) {
		var p trace.SchemeMakeDirectoryDoneInfo
		p.Error = e
		res(p)
	}
}
// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals
func SchemeOnRemoveDirectory(t *trace.Scheme, c *context.Context, c1 trace.Call, path string) func(error) {
	var p trace.SchemeRemoveDirectoryStartInfo
	p.Context = c
	p.Call = c1
	p.Path = path
	res := onRemoveDirectory(t, p)
	return func(e error) {
		var p trace.SchemeRemoveDirectoryDoneInfo
		p.Error = e
		res(p)
	}
}
// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals
func SchemeOnModifyPermissions(t *trace.Scheme, c *context.Context, c1 trace.Call, path string) func(error) {
	var p trace.SchemeModifyPermissionsStartInfo
	p.Context = c
	p.Call = c1
	p.Path = path
	res := onModifyPermissions(t, p)
	return func(e error) {
		var p trace.SchemeModifyPermissionsDoneInfo
		p.Error = e
		res(p)
	}
}
