// Code generated by github.com/actgardner/gogen-avro/v10. DO NOT EDIT.
/*
 * SOURCE:
 *     schema.avsc
 */
package avro

import (
	"encoding/json"
	"fmt"
	"io"

	"github.com/actgardner/gogen-avro/v10/compiler"
	"github.com/actgardner/gogen-avro/v10/vm"
	"github.com/actgardner/gogen-avro/v10/vm/types"
)

var _ = fmt.Printf

type ComCompanyTeamTypeOne struct {
	Type ComCompanyTeamSomeEnum `json:"type"`
}

const ComCompanyTeamTypeOneAvroCRC64Fingerprint = "\xc1b\xb9\x05Y9\xcf|"

func NewComCompanyTeamTypeOne() ComCompanyTeamTypeOne {
	r := ComCompanyTeamTypeOne{}
	return r
}

func DeserializeComCompanyTeamTypeOne(r io.Reader) (ComCompanyTeamTypeOne, error) {
	t := NewComCompanyTeamTypeOne()
	deser, err := compiler.CompileSchemaBytes([]byte(t.Schema()), []byte(t.Schema()))
	if err != nil {
		return t, err
	}

	err = vm.Eval(r, deser, &t)
	return t, err
}

func DeserializeComCompanyTeamTypeOneFromSchema(r io.Reader, schema string) (ComCompanyTeamTypeOne, error) {
	t := NewComCompanyTeamTypeOne()

	deser, err := compiler.CompileSchemaBytes([]byte(schema), []byte(t.Schema()))
	if err != nil {
		return t, err
	}

	err = vm.Eval(r, deser, &t)
	return t, err
}

func writeComCompanyTeamTypeOne(r ComCompanyTeamTypeOne, w io.Writer) error {
	var err error
	err = writeComCompanyTeamSomeEnum(r.Type, w)
	if err != nil {
		return err
	}
	return err
}

func (r ComCompanyTeamTypeOne) Serialize(w io.Writer) error {
	return writeComCompanyTeamTypeOne(r, w)
}

func (r ComCompanyTeamTypeOne) Schema() string {
	return "{\"fields\":[{\"name\":\"type\",\"type\":{\"name\":\"SomeEnum\",\"symbols\":[\"A\",\"B\",\"C\"],\"type\":\"enum\"}}],\"name\":\"com.company.team.TypeOne\",\"type\":\"record\"}"
}

func (r ComCompanyTeamTypeOne) SchemaName() string {
	return "com.company.team.TypeOne"
}

func (_ ComCompanyTeamTypeOne) SetBoolean(v bool)    { panic("Unsupported operation") }
func (_ ComCompanyTeamTypeOne) SetInt(v int32)       { panic("Unsupported operation") }
func (_ ComCompanyTeamTypeOne) SetLong(v int64)      { panic("Unsupported operation") }
func (_ ComCompanyTeamTypeOne) SetFloat(v float32)   { panic("Unsupported operation") }
func (_ ComCompanyTeamTypeOne) SetDouble(v float64)  { panic("Unsupported operation") }
func (_ ComCompanyTeamTypeOne) SetBytes(v []byte)    { panic("Unsupported operation") }
func (_ ComCompanyTeamTypeOne) SetString(v string)   { panic("Unsupported operation") }
func (_ ComCompanyTeamTypeOne) SetUnionElem(v int64) { panic("Unsupported operation") }

func (r *ComCompanyTeamTypeOne) Get(i int) types.Field {
	switch i {
	case 0:
		w := ComCompanyTeamSomeEnumWrapper{Target: &r.Type}

		return w

	}
	panic("Unknown field index")
}

func (r *ComCompanyTeamTypeOne) SetDefault(i int) {
	switch i {
	}
	panic("Unknown field index")
}

func (r *ComCompanyTeamTypeOne) NullField(i int) {
	switch i {
	}
	panic("Not a nullable field index")
}

func (_ ComCompanyTeamTypeOne) AppendMap(key string) types.Field { panic("Unsupported operation") }
func (_ ComCompanyTeamTypeOne) AppendArray() types.Field         { panic("Unsupported operation") }
func (_ ComCompanyTeamTypeOne) HintSize(int)                     { panic("Unsupported operation") }
func (_ ComCompanyTeamTypeOne) Finalize()                        {}

func (_ ComCompanyTeamTypeOne) AvroCRC64Fingerprint() []byte {
	return []byte(ComCompanyTeamTypeOneAvroCRC64Fingerprint)
}

func (r ComCompanyTeamTypeOne) MarshalJSON() ([]byte, error) {
	var err error
	output := make(map[string]json.RawMessage)
	output["type"], err = json.Marshal(r.Type)
	if err != nil {
		return nil, err
	}
	return json.Marshal(output)
}

func (r *ComCompanyTeamTypeOne) UnmarshalJSON(data []byte) error {
	var fields map[string]json.RawMessage
	if err := json.Unmarshal(data, &fields); err != nil {
		return err
	}

	var val json.RawMessage
	val = func() json.RawMessage {
		if v, ok := fields["type"]; ok {
			return v
		}
		return nil
	}()

	if val != nil {
		if err := json.Unmarshal([]byte(val), &r.Type); err != nil {
			return err
		}
	} else {
		return fmt.Errorf("no value specified for type")
	}
	return nil
}
