// Autogenerated by Thrift for thrift/compiler/test/fixtures/interactions/src/module.thrift
//
// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
//  @generated

package module


import (
    "context"
    "fmt"
    "reflect"

    shared "shared"
    thrift "github.com/facebook/fbthrift/thrift/lib/go/thrift/types"
    metadata "github.com/facebook/fbthrift/thrift/lib/thrift/metadata"
)

var _ = shared.GoUnusedProtection__
// (needed to ensure safety because of naive import list construction)
var _ = context.Background
var _ = fmt.Printf
var _ = reflect.Ptr
var _ = thrift.ZERO
var _ = metadata.GoUnusedProtection__

type MyService interface {
    Foo(ctx context.Context) (error)
}

type MyServiceChannelClientInterface interface {
    thrift.ClientInterface
    MyService
}

type MyServiceClientInterface interface {
    thrift.ClientInterface
    Foo() (error)
}

type MyServiceContextClientInterface interface {
    MyServiceClientInterface
    FooContext(ctx context.Context) (error)
}

type MyServiceChannelClient struct {
    ch thrift.RequestChannel
}
// Compile time interface enforcer
var _ MyServiceChannelClientInterface = (*MyServiceChannelClient)(nil)

func NewMyServiceChannelClient(channel thrift.RequestChannel) *MyServiceChannelClient {
    return &MyServiceChannelClient{
        ch: channel,
    }
}

func (c *MyServiceChannelClient) Close() error {
    return c.ch.Close()
}

type MyServiceClient struct {
    chClient *MyServiceChannelClient
}
// Compile time interface enforcer
var _ MyServiceClientInterface = (*MyServiceClient)(nil)
var _ MyServiceContextClientInterface = (*MyServiceClient)(nil)

func NewMyServiceClient(prot thrift.Protocol) *MyServiceClient {
    return &MyServiceClient{
        chClient: NewMyServiceChannelClient(
            thrift.NewSerialChannel(prot),
        ),
    }
}

func (c *MyServiceClient) Close() error {
    return c.chClient.Close()
}

func (c *MyServiceChannelClient) Foo(ctx context.Context) (error) {
    in := &reqMyServiceFoo{
    }
    out := newRespMyServiceFoo()
    err := c.ch.Call(ctx, "foo", in, out)
    if err != nil {
        return err
    }
    return nil
}

func (c *MyServiceClient) Foo() (error) {
    return c.chClient.Foo(context.Background())
}

func (c *MyServiceClient) FooContext(ctx context.Context) (error) {
    return c.chClient.Foo(ctx)
}


type MyServiceProcessor struct {
    processorFunctionMap map[string]thrift.ProcessorFunction
    functionServiceMap   map[string]string
    handler            MyService
}

func NewMyServiceProcessor(handler MyService) *MyServiceProcessor {
    p := &MyServiceProcessor{
        handler:              handler,
        processorFunctionMap: make(map[string]thrift.ProcessorFunction),
        functionServiceMap:   make(map[string]string),
    }
    p.AddToProcessorFunctionMap("foo", &procFuncMyServiceFoo{handler: handler})
    p.AddToFunctionServiceMap("foo", "MyService")

    return p
}

func (p *MyServiceProcessor) AddToProcessorFunctionMap(key string, processorFunction thrift.ProcessorFunction) {
    p.processorFunctionMap[key] = processorFunction
}

func (p *MyServiceProcessor) AddToFunctionServiceMap(key, service string) {
    p.functionServiceMap[key] = service
}

func (p *MyServiceProcessor) GetProcessorFunction(key string) (processor thrift.ProcessorFunction) {
    return p.processorFunctionMap[key]
}

func (p *MyServiceProcessor) ProcessorFunctionMap() map[string]thrift.ProcessorFunction {
    return p.processorFunctionMap
}

func (p *MyServiceProcessor) FunctionServiceMap() map[string]string {
    return p.functionServiceMap
}

func (p *MyServiceProcessor) PackageName() string {
    return "module"
}

func (p *MyServiceProcessor) GetThriftMetadata() *metadata.ThriftMetadata {
    return GetThriftMetadataForService("module.MyService")
}


type procFuncMyServiceFoo struct {
    handler MyService
}
// Compile time interface enforcer
var _ thrift.ProcessorFunction = (*procFuncMyServiceFoo)(nil)

func (p *procFuncMyServiceFoo) Read(iprot thrift.Decoder) (thrift.Struct, thrift.Exception) {
    args := newReqMyServiceFoo()
    if err := args.Read(iprot); err != nil {
        return nil, err
    }
    iprot.ReadMessageEnd()
    return args, nil
}

func (p *procFuncMyServiceFoo) Write(seqId int32, result thrift.WritableStruct, oprot thrift.Encoder) (err thrift.Exception) {
    var err2 error
    messageType := thrift.REPLY
    switch result.(type) {
    case thrift.ApplicationException:
        messageType = thrift.EXCEPTION
    }

    if err2 = oprot.WriteMessageBegin("foo", messageType, seqId); err2 != nil {
        err = err2
    }
    if err2 = result.Write(oprot); err == nil && err2 != nil {
        err = err2
    }
    if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil {
        err = err2
    }
    if err2 = oprot.Flush(); err == nil && err2 != nil {
        err = err2
    }
    return err
}

func (p *procFuncMyServiceFoo) RunContext(ctx context.Context, reqStruct thrift.Struct) (thrift.WritableStruct, thrift.ApplicationException) {
    result := newRespMyServiceFoo()
    err := p.handler.Foo(ctx)
    if err != nil {
        x := thrift.NewApplicationExceptionCause(thrift.INTERNAL_ERROR, "Internal error processing Foo: " + err.Error(), err)
        return x, x
    }

    return result, nil
}


type Factories interface {
    Foo(ctx context.Context) (error)
}

type FactoriesChannelClientInterface interface {
    thrift.ClientInterface
    Factories
}

type FactoriesClientInterface interface {
    thrift.ClientInterface
    Foo() (error)
}

type FactoriesContextClientInterface interface {
    FactoriesClientInterface
    FooContext(ctx context.Context) (error)
}

type FactoriesChannelClient struct {
    ch thrift.RequestChannel
}
// Compile time interface enforcer
var _ FactoriesChannelClientInterface = (*FactoriesChannelClient)(nil)

func NewFactoriesChannelClient(channel thrift.RequestChannel) *FactoriesChannelClient {
    return &FactoriesChannelClient{
        ch: channel,
    }
}

func (c *FactoriesChannelClient) Close() error {
    return c.ch.Close()
}

type FactoriesClient struct {
    chClient *FactoriesChannelClient
}
// Compile time interface enforcer
var _ FactoriesClientInterface = (*FactoriesClient)(nil)
var _ FactoriesContextClientInterface = (*FactoriesClient)(nil)

func NewFactoriesClient(prot thrift.Protocol) *FactoriesClient {
    return &FactoriesClient{
        chClient: NewFactoriesChannelClient(
            thrift.NewSerialChannel(prot),
        ),
    }
}

func (c *FactoriesClient) Close() error {
    return c.chClient.Close()
}

func (c *FactoriesChannelClient) Foo(ctx context.Context) (error) {
    in := &reqFactoriesFoo{
    }
    out := newRespFactoriesFoo()
    err := c.ch.Call(ctx, "foo", in, out)
    if err != nil {
        return err
    }
    return nil
}

func (c *FactoriesClient) Foo() (error) {
    return c.chClient.Foo(context.Background())
}

func (c *FactoriesClient) FooContext(ctx context.Context) (error) {
    return c.chClient.Foo(ctx)
}


type FactoriesProcessor struct {
    processorFunctionMap map[string]thrift.ProcessorFunction
    functionServiceMap   map[string]string
    handler            Factories
}

func NewFactoriesProcessor(handler Factories) *FactoriesProcessor {
    p := &FactoriesProcessor{
        handler:              handler,
        processorFunctionMap: make(map[string]thrift.ProcessorFunction),
        functionServiceMap:   make(map[string]string),
    }
    p.AddToProcessorFunctionMap("foo", &procFuncFactoriesFoo{handler: handler})
    p.AddToFunctionServiceMap("foo", "Factories")

    return p
}

func (p *FactoriesProcessor) AddToProcessorFunctionMap(key string, processorFunction thrift.ProcessorFunction) {
    p.processorFunctionMap[key] = processorFunction
}

func (p *FactoriesProcessor) AddToFunctionServiceMap(key, service string) {
    p.functionServiceMap[key] = service
}

func (p *FactoriesProcessor) GetProcessorFunction(key string) (processor thrift.ProcessorFunction) {
    return p.processorFunctionMap[key]
}

func (p *FactoriesProcessor) ProcessorFunctionMap() map[string]thrift.ProcessorFunction {
    return p.processorFunctionMap
}

func (p *FactoriesProcessor) FunctionServiceMap() map[string]string {
    return p.functionServiceMap
}

func (p *FactoriesProcessor) PackageName() string {
    return "module"
}

func (p *FactoriesProcessor) GetThriftMetadata() *metadata.ThriftMetadata {
    return GetThriftMetadataForService("module.Factories")
}


type procFuncFactoriesFoo struct {
    handler Factories
}
// Compile time interface enforcer
var _ thrift.ProcessorFunction = (*procFuncFactoriesFoo)(nil)

func (p *procFuncFactoriesFoo) Read(iprot thrift.Decoder) (thrift.Struct, thrift.Exception) {
    args := newReqFactoriesFoo()
    if err := args.Read(iprot); err != nil {
        return nil, err
    }
    iprot.ReadMessageEnd()
    return args, nil
}

func (p *procFuncFactoriesFoo) Write(seqId int32, result thrift.WritableStruct, oprot thrift.Encoder) (err thrift.Exception) {
    var err2 error
    messageType := thrift.REPLY
    switch result.(type) {
    case thrift.ApplicationException:
        messageType = thrift.EXCEPTION
    }

    if err2 = oprot.WriteMessageBegin("foo", messageType, seqId); err2 != nil {
        err = err2
    }
    if err2 = result.Write(oprot); err == nil && err2 != nil {
        err = err2
    }
    if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil {
        err = err2
    }
    if err2 = oprot.Flush(); err == nil && err2 != nil {
        err = err2
    }
    return err
}

func (p *procFuncFactoriesFoo) RunContext(ctx context.Context, reqStruct thrift.Struct) (thrift.WritableStruct, thrift.ApplicationException) {
    result := newRespFactoriesFoo()
    err := p.handler.Foo(ctx)
    if err != nil {
        x := thrift.NewApplicationExceptionCause(thrift.INTERNAL_ERROR, "Internal error processing Foo: " + err.Error(), err)
        return x, x
    }

    return result, nil
}


type Perform interface {
    Foo(ctx context.Context) (error)
}

type PerformChannelClientInterface interface {
    thrift.ClientInterface
    Perform
}

type PerformClientInterface interface {
    thrift.ClientInterface
    Foo() (error)
}

type PerformContextClientInterface interface {
    PerformClientInterface
    FooContext(ctx context.Context) (error)
}

type PerformChannelClient struct {
    ch thrift.RequestChannel
}
// Compile time interface enforcer
var _ PerformChannelClientInterface = (*PerformChannelClient)(nil)

func NewPerformChannelClient(channel thrift.RequestChannel) *PerformChannelClient {
    return &PerformChannelClient{
        ch: channel,
    }
}

func (c *PerformChannelClient) Close() error {
    return c.ch.Close()
}

type PerformClient struct {
    chClient *PerformChannelClient
}
// Compile time interface enforcer
var _ PerformClientInterface = (*PerformClient)(nil)
var _ PerformContextClientInterface = (*PerformClient)(nil)

func NewPerformClient(prot thrift.Protocol) *PerformClient {
    return &PerformClient{
        chClient: NewPerformChannelClient(
            thrift.NewSerialChannel(prot),
        ),
    }
}

func (c *PerformClient) Close() error {
    return c.chClient.Close()
}

func (c *PerformChannelClient) Foo(ctx context.Context) (error) {
    in := &reqPerformFoo{
    }
    out := newRespPerformFoo()
    err := c.ch.Call(ctx, "foo", in, out)
    if err != nil {
        return err
    }
    return nil
}

func (c *PerformClient) Foo() (error) {
    return c.chClient.Foo(context.Background())
}

func (c *PerformClient) FooContext(ctx context.Context) (error) {
    return c.chClient.Foo(ctx)
}


type PerformProcessor struct {
    processorFunctionMap map[string]thrift.ProcessorFunction
    functionServiceMap   map[string]string
    handler            Perform
}

func NewPerformProcessor(handler Perform) *PerformProcessor {
    p := &PerformProcessor{
        handler:              handler,
        processorFunctionMap: make(map[string]thrift.ProcessorFunction),
        functionServiceMap:   make(map[string]string),
    }
    p.AddToProcessorFunctionMap("foo", &procFuncPerformFoo{handler: handler})
    p.AddToFunctionServiceMap("foo", "Perform")

    return p
}

func (p *PerformProcessor) AddToProcessorFunctionMap(key string, processorFunction thrift.ProcessorFunction) {
    p.processorFunctionMap[key] = processorFunction
}

func (p *PerformProcessor) AddToFunctionServiceMap(key, service string) {
    p.functionServiceMap[key] = service
}

func (p *PerformProcessor) GetProcessorFunction(key string) (processor thrift.ProcessorFunction) {
    return p.processorFunctionMap[key]
}

func (p *PerformProcessor) ProcessorFunctionMap() map[string]thrift.ProcessorFunction {
    return p.processorFunctionMap
}

func (p *PerformProcessor) FunctionServiceMap() map[string]string {
    return p.functionServiceMap
}

func (p *PerformProcessor) PackageName() string {
    return "module"
}

func (p *PerformProcessor) GetThriftMetadata() *metadata.ThriftMetadata {
    return GetThriftMetadataForService("module.Perform")
}


type procFuncPerformFoo struct {
    handler Perform
}
// Compile time interface enforcer
var _ thrift.ProcessorFunction = (*procFuncPerformFoo)(nil)

func (p *procFuncPerformFoo) Read(iprot thrift.Decoder) (thrift.Struct, thrift.Exception) {
    args := newReqPerformFoo()
    if err := args.Read(iprot); err != nil {
        return nil, err
    }
    iprot.ReadMessageEnd()
    return args, nil
}

func (p *procFuncPerformFoo) Write(seqId int32, result thrift.WritableStruct, oprot thrift.Encoder) (err thrift.Exception) {
    var err2 error
    messageType := thrift.REPLY
    switch result.(type) {
    case thrift.ApplicationException:
        messageType = thrift.EXCEPTION
    }

    if err2 = oprot.WriteMessageBegin("foo", messageType, seqId); err2 != nil {
        err = err2
    }
    if err2 = result.Write(oprot); err == nil && err2 != nil {
        err = err2
    }
    if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil {
        err = err2
    }
    if err2 = oprot.Flush(); err == nil && err2 != nil {
        err = err2
    }
    return err
}

func (p *procFuncPerformFoo) RunContext(ctx context.Context, reqStruct thrift.Struct) (thrift.WritableStruct, thrift.ApplicationException) {
    result := newRespPerformFoo()
    err := p.handler.Foo(ctx)
    if err != nil {
        x := thrift.NewApplicationExceptionCause(thrift.INTERNAL_ERROR, "Internal error processing Foo: " + err.Error(), err)
        return x, x
    }

    return result, nil
}


type InteractWithShared interface {
    DoSomeSimilarThings(ctx context.Context) (*shared.DoSomethingResult, error)
}

type InteractWithSharedChannelClientInterface interface {
    thrift.ClientInterface
    InteractWithShared
}

type InteractWithSharedClientInterface interface {
    thrift.ClientInterface
    DoSomeSimilarThings() (*shared.DoSomethingResult, error)
}

type InteractWithSharedContextClientInterface interface {
    InteractWithSharedClientInterface
    DoSomeSimilarThingsContext(ctx context.Context) (*shared.DoSomethingResult, error)
}

type InteractWithSharedChannelClient struct {
    ch thrift.RequestChannel
}
// Compile time interface enforcer
var _ InteractWithSharedChannelClientInterface = (*InteractWithSharedChannelClient)(nil)

func NewInteractWithSharedChannelClient(channel thrift.RequestChannel) *InteractWithSharedChannelClient {
    return &InteractWithSharedChannelClient{
        ch: channel,
    }
}

func (c *InteractWithSharedChannelClient) Close() error {
    return c.ch.Close()
}

type InteractWithSharedClient struct {
    chClient *InteractWithSharedChannelClient
}
// Compile time interface enforcer
var _ InteractWithSharedClientInterface = (*InteractWithSharedClient)(nil)
var _ InteractWithSharedContextClientInterface = (*InteractWithSharedClient)(nil)

func NewInteractWithSharedClient(prot thrift.Protocol) *InteractWithSharedClient {
    return &InteractWithSharedClient{
        chClient: NewInteractWithSharedChannelClient(
            thrift.NewSerialChannel(prot),
        ),
    }
}

func (c *InteractWithSharedClient) Close() error {
    return c.chClient.Close()
}

func (c *InteractWithSharedChannelClient) DoSomeSimilarThings(ctx context.Context) (*shared.DoSomethingResult, error) {
    in := &reqInteractWithSharedDoSomeSimilarThings{
    }
    out := newRespInteractWithSharedDoSomeSimilarThings()
    err := c.ch.Call(ctx, "do_some_similar_things", in, out)
    if err != nil {
        return nil, err
    }
    return out.GetSuccess(), nil
}

func (c *InteractWithSharedClient) DoSomeSimilarThings() (*shared.DoSomethingResult, error) {
    return c.chClient.DoSomeSimilarThings(context.Background())
}

func (c *InteractWithSharedClient) DoSomeSimilarThingsContext(ctx context.Context) (*shared.DoSomethingResult, error) {
    return c.chClient.DoSomeSimilarThings(ctx)
}


type InteractWithSharedProcessor struct {
    processorFunctionMap map[string]thrift.ProcessorFunction
    functionServiceMap   map[string]string
    handler            InteractWithShared
}

func NewInteractWithSharedProcessor(handler InteractWithShared) *InteractWithSharedProcessor {
    p := &InteractWithSharedProcessor{
        handler:              handler,
        processorFunctionMap: make(map[string]thrift.ProcessorFunction),
        functionServiceMap:   make(map[string]string),
    }
    p.AddToProcessorFunctionMap("do_some_similar_things", &procFuncInteractWithSharedDoSomeSimilarThings{handler: handler})
    p.AddToFunctionServiceMap("do_some_similar_things", "InteractWithShared")

    return p
}

func (p *InteractWithSharedProcessor) AddToProcessorFunctionMap(key string, processorFunction thrift.ProcessorFunction) {
    p.processorFunctionMap[key] = processorFunction
}

func (p *InteractWithSharedProcessor) AddToFunctionServiceMap(key, service string) {
    p.functionServiceMap[key] = service
}

func (p *InteractWithSharedProcessor) GetProcessorFunction(key string) (processor thrift.ProcessorFunction) {
    return p.processorFunctionMap[key]
}

func (p *InteractWithSharedProcessor) ProcessorFunctionMap() map[string]thrift.ProcessorFunction {
    return p.processorFunctionMap
}

func (p *InteractWithSharedProcessor) FunctionServiceMap() map[string]string {
    return p.functionServiceMap
}

func (p *InteractWithSharedProcessor) PackageName() string {
    return "module"
}

func (p *InteractWithSharedProcessor) GetThriftMetadata() *metadata.ThriftMetadata {
    return GetThriftMetadataForService("module.InteractWithShared")
}


type procFuncInteractWithSharedDoSomeSimilarThings struct {
    handler InteractWithShared
}
// Compile time interface enforcer
var _ thrift.ProcessorFunction = (*procFuncInteractWithSharedDoSomeSimilarThings)(nil)

func (p *procFuncInteractWithSharedDoSomeSimilarThings) Read(iprot thrift.Decoder) (thrift.Struct, thrift.Exception) {
    args := newReqInteractWithSharedDoSomeSimilarThings()
    if err := args.Read(iprot); err != nil {
        return nil, err
    }
    iprot.ReadMessageEnd()
    return args, nil
}

func (p *procFuncInteractWithSharedDoSomeSimilarThings) Write(seqId int32, result thrift.WritableStruct, oprot thrift.Encoder) (err thrift.Exception) {
    var err2 error
    messageType := thrift.REPLY
    switch result.(type) {
    case thrift.ApplicationException:
        messageType = thrift.EXCEPTION
    }

    if err2 = oprot.WriteMessageBegin("do_some_similar_things", messageType, seqId); err2 != nil {
        err = err2
    }
    if err2 = result.Write(oprot); err == nil && err2 != nil {
        err = err2
    }
    if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil {
        err = err2
    }
    if err2 = oprot.Flush(); err == nil && err2 != nil {
        err = err2
    }
    return err
}

func (p *procFuncInteractWithSharedDoSomeSimilarThings) RunContext(ctx context.Context, reqStruct thrift.Struct) (thrift.WritableStruct, thrift.ApplicationException) {
    result := newRespInteractWithSharedDoSomeSimilarThings()
    retval, err := p.handler.DoSomeSimilarThings(ctx)
    if err != nil {
        x := thrift.NewApplicationExceptionCause(thrift.INTERNAL_ERROR, "Internal error processing DoSomeSimilarThings: " + err.Error(), err)
        return x, x
    }

    result.Success = retval
    return result, nil
}


