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

package module


import (
    "context"
    "fmt"
    "reflect"

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

// (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 TestService interface {
    Init(ctx context.Context, int1 int64) (int64, error)
}

type TestServiceChannelClientInterface interface {
    thrift.ClientInterface
    TestService
}

type TestServiceClientInterface interface {
    thrift.ClientInterface
    Init(int1 int64) (int64, error)
}

type TestServiceContextClientInterface interface {
    TestServiceClientInterface
    InitContext(ctx context.Context, int1 int64) (int64, error)
}

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

func NewTestServiceChannelClient(channel thrift.RequestChannel) *TestServiceChannelClient {
    return &TestServiceChannelClient{
        ch: channel,
    }
}

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

type TestServiceClient struct {
    chClient *TestServiceChannelClient
}
// Compile time interface enforcer
var _ TestServiceClientInterface = (*TestServiceClient)(nil)
var _ TestServiceContextClientInterface = (*TestServiceClient)(nil)

func NewTestServiceClient(prot thrift.Protocol) *TestServiceClient {
    return &TestServiceClient{
        chClient: NewTestServiceChannelClient(
            thrift.NewSerialChannel(prot),
        ),
    }
}

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

func (c *TestServiceChannelClient) Init(ctx context.Context, int1 int64) (int64, error) {
    in := &reqTestServiceInit{
        Int1: int1,
    }
    out := newRespTestServiceInit()
    err := c.ch.Call(ctx, "init", in, out)
    if err != nil {
        return 0, err
    }
    return out.GetSuccess(), nil
}

func (c *TestServiceClient) Init(int1 int64) (int64, error) {
    return c.chClient.Init(context.Background(), int1)
}

func (c *TestServiceClient) InitContext(ctx context.Context, int1 int64) (int64, error) {
    return c.chClient.Init(ctx, int1)
}


type TestServiceProcessor struct {
    processorFunctionMap map[string]thrift.ProcessorFunction
    functionServiceMap   map[string]string
    handler            TestService
}

func NewTestServiceProcessor(handler TestService) *TestServiceProcessor {
    p := &TestServiceProcessor{
        handler:              handler,
        processorFunctionMap: make(map[string]thrift.ProcessorFunction),
        functionServiceMap:   make(map[string]string),
    }
    p.AddToProcessorFunctionMap("init", &procFuncTestServiceInit{handler: handler})
    p.AddToFunctionServiceMap("init", "TestService")

    return p
}

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

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

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

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

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

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

func (p *TestServiceProcessor) GetThriftMetadata() *metadata.ThriftMetadata {
    return GetThriftMetadataForService("module.TestService")
}


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

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

func (p *procFuncTestServiceInit) 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("init", 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 *procFuncTestServiceInit) RunContext(ctx context.Context, reqStruct thrift.Struct) (thrift.WritableStruct, thrift.ApplicationException) {
    args := reqStruct.(*reqTestServiceInit)
    result := newRespTestServiceInit()
    retval, err := p.handler.Init(ctx, args.Int1)
    if err != nil {
        x := thrift.NewApplicationExceptionCause(thrift.INTERNAL_ERROR, "Internal error processing Init: " + err.Error(), err)
        return x, x
    }

    result.Success = &retval
    return result, nil
}


