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

package matching_names

import (
    "fmt"
    "reflect"

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

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

type IncludesAlso struct {
    Also *includesAlso.Also `thrift:"also,1" json:"also" db:"also"`
}
// Compile time interface enforcer
var _ thrift.Struct = (*IncludesAlso)(nil)

func NewIncludesAlso() *IncludesAlso {
    return (&IncludesAlso{}).setDefaults()
}

func (x *IncludesAlso) GetAlso() *includesAlso.Also {
    if !x.IsSetAlso() {
        return nil
    }
    return x.Also
}

func (x *IncludesAlso) SetAlsoNonCompat(value *includesAlso.Also) *IncludesAlso {
    x.Also = value
    return x
}

func (x *IncludesAlso) SetAlso(value *includesAlso.Also) *IncludesAlso {
    x.Also = value
    return x
}

func (x *IncludesAlso) IsSetAlso() bool {
    return x != nil && x.Also != nil
}

func (x *IncludesAlso) writeField1(p thrift.Encoder) error {  // Also
    if !x.IsSetAlso() {
        return nil
    }

    if err := p.WriteFieldBegin("also", thrift.STRUCT, 1); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field begin error: ", x), err)
    }

    item := x.Also
    if err := item.Write(p); err != nil {
        return err
    }

    if err := p.WriteFieldEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field end error: ", x), err)
    }
    return nil
}

func (x *IncludesAlso) readField1(p thrift.Decoder) error {  // Also
    result := includesAlso.NewAlso()
    err := result.Read(p)
    if err != nil {
        return err
    }

    x.Also = result
    return nil
}

// Deprecated: Use NewIncludesAlso().GetAlso() instead.
func (x *IncludesAlso) DefaultGetAlso() *includesAlso.Also {
    if !x.IsSetAlso() {
        return includesAlso.NewAlso()
    }
    return x.Also
}



func (x *IncludesAlso) Write(p thrift.Encoder) error {
    if err := p.WriteStructBegin("IncludesAlso"); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", x), err)
    }

    if err := x.writeField1(p); err != nil {
        return err
    }

    if err := p.WriteFieldStop(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", x), err)
    }

    if err := p.WriteStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", x), err)
    }
    return nil
}

func (x *IncludesAlso) Read(p thrift.Decoder) error {
    if _, err := p.ReadStructBegin(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read error: ", x), err)
    }

    for {
        _, wireType, id, err := p.ReadFieldBegin()
        if err != nil {
            return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", x, id), err)
        }

        if wireType == thrift.STOP {
            break;
        }

        var fieldReadErr error
        switch {
        case (id == 1 && wireType == thrift.Type(thrift.STRUCT)):  // also
            fieldReadErr = x.readField1(p)
        default:
            fieldReadErr = p.Skip(wireType)
        }

        if fieldReadErr != nil {
            return fieldReadErr
        }

        if err := p.ReadFieldEnd(); err != nil {
            return err
        }
    }

    if err := p.ReadStructEnd(); err != nil {
        return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", x), err)
    }

    return nil
}

func (x *IncludesAlso) String() string {
    return thrift.StructToString(reflect.ValueOf(x))
}

func (x *IncludesAlso) setDefaults() *IncludesAlso {
    return x.
        SetAlsoNonCompat(includesAlso.NewAlso())
}



// RegisterTypes registers types found in this file that have a thrift_uri with the passed in registry.
func RegisterTypes(registry interface {
  RegisterType(name string, initializer func() any)
}) {

}
