// 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 ConflictingNamespaceFixedTestRecord struct {
	FixedFieldOne ComCompanyTeamConflictingFixedType `json:"fixedFieldOne"`

	FixedFieldTwo ComCompanySharedConflictingFixedType `json:"fixedFieldTwo"`
}

const ConflictingNamespaceFixedTestRecordAvroCRC64Fingerprint = "\xac\xa49=o\x88\x9d\xde"

func NewConflictingNamespaceFixedTestRecord() ConflictingNamespaceFixedTestRecord {
	r := ConflictingNamespaceFixedTestRecord{}
	return r
}

func DeserializeConflictingNamespaceFixedTestRecord(r io.Reader) (ConflictingNamespaceFixedTestRecord, error) {
	t := NewConflictingNamespaceFixedTestRecord()
	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 DeserializeConflictingNamespaceFixedTestRecordFromSchema(r io.Reader, schema string) (ConflictingNamespaceFixedTestRecord, error) {
	t := NewConflictingNamespaceFixedTestRecord()

	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 writeConflictingNamespaceFixedTestRecord(r ConflictingNamespaceFixedTestRecord, w io.Writer) error {
	var err error
	err = writeComCompanyTeamConflictingFixedType(r.FixedFieldOne, w)
	if err != nil {
		return err
	}
	err = writeComCompanySharedConflictingFixedType(r.FixedFieldTwo, w)
	if err != nil {
		return err
	}
	return err
}

func (r ConflictingNamespaceFixedTestRecord) Serialize(w io.Writer) error {
	return writeConflictingNamespaceFixedTestRecord(r, w)
}

func (r ConflictingNamespaceFixedTestRecord) Schema() string {
	return "{\"fields\":[{\"name\":\"fixedFieldOne\",\"type\":{\"name\":\"ConflictingFixedType\",\"namespace\":\"com.company.team\",\"size\":1,\"type\":\"fixed\"}},{\"name\":\"fixedFieldTwo\",\"type\":{\"name\":\"ConflictingFixedType\",\"namespace\":\"com.company.shared\",\"size\":2,\"type\":\"fixed\"}}],\"name\":\"ConflictingNamespaceFixedTestRecord\",\"type\":\"record\"}"
}

func (r ConflictingNamespaceFixedTestRecord) SchemaName() string {
	return "ConflictingNamespaceFixedTestRecord"
}

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

func (r *ConflictingNamespaceFixedTestRecord) Get(i int) types.Field {
	switch i {
	case 0:
		w := ComCompanyTeamConflictingFixedTypeWrapper{Target: &r.FixedFieldOne}

		return w

	case 1:
		w := ComCompanySharedConflictingFixedTypeWrapper{Target: &r.FixedFieldTwo}

		return w

	}
	panic("Unknown field index")
}

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

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

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

func (_ ConflictingNamespaceFixedTestRecord) AvroCRC64Fingerprint() []byte {
	return []byte(ConflictingNamespaceFixedTestRecordAvroCRC64Fingerprint)
}

func (r ConflictingNamespaceFixedTestRecord) MarshalJSON() ([]byte, error) {
	var err error
	output := make(map[string]json.RawMessage)
	output["fixedFieldOne"], err = json.Marshal(r.FixedFieldOne)
	if err != nil {
		return nil, err
	}
	output["fixedFieldTwo"], err = json.Marshal(r.FixedFieldTwo)
	if err != nil {
		return nil, err
	}
	return json.Marshal(output)
}

func (r *ConflictingNamespaceFixedTestRecord) 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["fixedFieldOne"]; ok {
			return v
		}
		return nil
	}()

	if val != nil {
		if err := json.Unmarshal([]byte(val), &r.FixedFieldOne); err != nil {
			return err
		}
	} else {
		return fmt.Errorf("no value specified for fixedFieldOne")
	}
	val = func() json.RawMessage {
		if v, ok := fields["fixedFieldTwo"]; ok {
			return v
		}
		return nil
	}()

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