package chaintypes

import (
	ipld "github.com/ipld/go-ipld-prime"
	"github.com/ipld/go-ipld-prime/node/mixins"
	"github.com/ipld/go-ipld-prime/schema"
)

type _Parents struct {
	x []_Link
}
type Parents = *_Parents
type _Parents__Maybe struct {
	m schema.Maybe
	v Parents
}
type MaybeParents = *_Parents__Maybe

func (m MaybeParents) IsNull() bool {
	return m.m == schema.Maybe_Null
}
func (m MaybeParents) IsAbsent() bool {
	return m.m == schema.Maybe_Absent
}
func (m MaybeParents) Exists() bool {
	return m.m == schema.Maybe_Value
}
func (m MaybeParents) AsNode() ipld.Node {
	switch m.m {
	case schema.Maybe_Absent:
		return ipld.Absent
	case schema.Maybe_Null:
		return ipld.Null
	case schema.Maybe_Value:
		return m.v
	default:
		panic("unreachable")
	}
}
func (m MaybeParents) Must() Parents {
	if !m.Exists() {
		panic("unbox of a maybe rejected")
	}
	return m.v
}

var _ ipld.Node = (Parents)(&_Parents{})
var _ schema.TypedNode = (Parents)(&_Parents{})

func (Parents) ReprKind() ipld.ReprKind {
	return ipld.ReprKind_List
}
func (Parents) LookupByString(string) (ipld.Node, error) {
	return mixins.List{"chaintypes.Parents"}.LookupByString("")
}
func (n Parents) LookupByNode(k ipld.Node) (ipld.Node, error) {
	idx, err := k.AsInt()
	if err != nil {
		return nil, err
	}
	return n.LookupByIndex(idx)
}
func (n Parents) LookupByIndex(idx int) (ipld.Node, error) {
	if n.Length() <= idx {
		return nil, ipld.ErrNotExists{ipld.PathSegmentOfInt(idx)}
	}
	v := &n.x[idx]
	return v, nil
}
func (n Parents) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) {
	i, err := seg.Index()
	if err != nil {
		return nil, ipld.ErrInvalidSegmentForList{TypeName: "chaintypes.Parents", TroubleSegment: seg, Reason: err}
	}
	return n.LookupByIndex(i)
}
func (Parents) MapIterator() ipld.MapIterator {
	return nil
}
func (n Parents) ListIterator() ipld.ListIterator {
	return &_Parents__ListItr{n, 0}
}

type _Parents__ListItr struct {
	n   Parents
	idx int
}

func (itr *_Parents__ListItr) Next() (idx int, v ipld.Node, _ error) {
	if itr.idx >= len(itr.n.x) {
		return -1, nil, ipld.ErrIteratorOverread{}
	}
	idx = itr.idx
	x := &itr.n.x[itr.idx]
	v = x
	itr.idx++
	return
}
func (itr *_Parents__ListItr) Done() bool {
	return itr.idx >= len(itr.n.x)
}

func (n Parents) Length() int {
	return len(n.x)
}
func (Parents) IsAbsent() bool {
	return false
}
func (Parents) IsNull() bool {
	return false
}
func (Parents) AsBool() (bool, error) {
	return mixins.List{"chaintypes.Parents"}.AsBool()
}
func (Parents) AsInt() (int, error) {
	return mixins.List{"chaintypes.Parents"}.AsInt()
}
func (Parents) AsFloat() (float64, error) {
	return mixins.List{"chaintypes.Parents"}.AsFloat()
}
func (Parents) AsString() (string, error) {
	return mixins.List{"chaintypes.Parents"}.AsString()
}
func (Parents) AsBytes() ([]byte, error) {
	return mixins.List{"chaintypes.Parents"}.AsBytes()
}
func (Parents) AsLink() (ipld.Link, error) {
	return mixins.List{"chaintypes.Parents"}.AsLink()
}
func (Parents) Prototype() ipld.NodePrototype {
	return _Parents__Prototype{}
}

type _Parents__Prototype struct{}

func (_Parents__Prototype) NewBuilder() ipld.NodeBuilder {
	var nb _Parents__Builder
	nb.Reset()
	return &nb
}

type _Parents__Builder struct {
	_Parents__Assembler
}

func (nb *_Parents__Builder) Build() ipld.Node {
	if *nb.m != schema.Maybe_Value {
		panic("invalid state: cannot call Build on an assembler that's not finished")
	}
	return nb.w
}
func (nb *_Parents__Builder) Reset() {
	var w _Parents
	var m schema.Maybe
	*nb = _Parents__Builder{_Parents__Assembler{w: &w, m: &m}}
}

type _Parents__Assembler struct {
	w     *_Parents
	m     *schema.Maybe
	state laState

	cm schema.Maybe
	va _Link__Assembler
}

func (na *_Parents__Assembler) reset() {
	na.state = laState_initial
	na.va.reset()
}
func (_Parents__Assembler) BeginMap(sizeHint int) (ipld.MapAssembler, error) {
	return mixins.ListAssembler{"chaintypes.Parents"}.BeginMap(0)
}
func (na *_Parents__Assembler) BeginList(sizeHint int) (ipld.ListAssembler, error) {
	switch *na.m {
	case schema.Maybe_Value, schema.Maybe_Null:
		panic("invalid state: cannot assign into assembler that's already finished")
	case midvalue:
		panic("invalid state: it makes no sense to 'begin' twice on the same assembler!")
	}
	*na.m = midvalue
	if sizeHint < 0 {
		sizeHint = 0
	}
	if na.w == nil {
		na.w = &_Parents{}
	}
	if sizeHint > 0 {
		na.w.x = make([]_Link, 0, sizeHint)
	}
	return na, nil
}
func (na *_Parents__Assembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.ListAssembler{"chaintypes.Parents"}.AssignNull()
	case schema.Maybe_Value, schema.Maybe_Null:
		panic("invalid state: cannot assign into assembler that's already finished")
	case midvalue:
		panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!")
	}
	panic("unreachable")
}
func (_Parents__Assembler) AssignBool(bool) error {
	return mixins.ListAssembler{"chaintypes.Parents"}.AssignBool(false)
}
func (_Parents__Assembler) AssignInt(int) error {
	return mixins.ListAssembler{"chaintypes.Parents"}.AssignInt(0)
}
func (_Parents__Assembler) AssignFloat(float64) error {
	return mixins.ListAssembler{"chaintypes.Parents"}.AssignFloat(0)
}
func (_Parents__Assembler) AssignString(string) error {
	return mixins.ListAssembler{"chaintypes.Parents"}.AssignString("")
}
func (_Parents__Assembler) AssignBytes([]byte) error {
	return mixins.ListAssembler{"chaintypes.Parents"}.AssignBytes(nil)
}
func (_Parents__Assembler) AssignLink(ipld.Link) error {
	return mixins.ListAssembler{"chaintypes.Parents"}.AssignLink(nil)
}
func (na *_Parents__Assembler) AssignNode(v ipld.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_Parents); ok {
		switch *na.m {
		case schema.Maybe_Value, schema.Maybe_Null:
			panic("invalid state: cannot assign into assembler that's already finished")
		case midvalue:
			panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!")
		}
		if na.w == nil {
			na.w = v2
			*na.m = schema.Maybe_Value
			return nil
		}
		*na.w = *v2
		*na.m = schema.Maybe_Value
		return nil
	}
	if v.ReprKind() != ipld.ReprKind_List {
		return ipld.ErrWrongKind{TypeName: "chaintypes.Parents", MethodName: "AssignNode", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: v.ReprKind()}
	}
	itr := v.ListIterator()
	for !itr.Done() {
		_, v, err := itr.Next()
		if err != nil {
			return err
		}
		if err := na.AssembleValue().AssignNode(v); err != nil {
			return err
		}
	}
	return na.Finish()
}
func (_Parents__Assembler) Prototype() ipld.NodePrototype {
	return _Parents__Prototype{}
}
func (la *_Parents__Assembler) valueFinishTidy() bool {
	switch la.cm {
	case schema.Maybe_Value:
		la.va.w = nil
		la.cm = schema.Maybe_Absent
		la.state = laState_initial
		la.va.reset()
		return true
	default:
		return false
	}
}
func (la *_Parents__Assembler) AssembleValue() ipld.NodeAssembler {
	switch la.state {
	case laState_initial:

	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value")
		} 
	case laState_finished:
		panic("invalid state: AssembleValue cannot be called on an assembler that's already finished")
	}
	la.w.x = append(la.w.x, _Link{})
	la.state = laState_midValue
	row := &la.w.x[len(la.w.x)-1]
	la.va.w = row
	la.va.m = &la.cm
	return &la.va
}
func (la *_Parents__Assembler) Finish() error {
	switch la.state {
	case laState_initial:

	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: Finish cannot be called when in the middle of assembling a value")
		} 
	case laState_finished:
		panic("invalid state: Finish cannot be called on an assembler that's already finished")
	}
	la.state = laState_finished
	*la.m = schema.Maybe_Value
	return nil
}
func (la *_Parents__Assembler) ValuePrototype(_ int) ipld.NodePrototype {
	return _Link__Prototype{}
}
func (Parents) Type() schema.Type {
	return nil 
}
func (n Parents) Representation() ipld.Node {
	return (*_Parents__Repr)(n)
}

type _Parents__Repr _Parents

var _ ipld.Node = &_Parents__Repr{}

func (_Parents__Repr) ReprKind() ipld.ReprKind {
	return ipld.ReprKind_List
}
func (_Parents__Repr) LookupByString(string) (ipld.Node, error) {
	return mixins.List{"chaintypes.Parents.Repr"}.LookupByString("")
}
func (nr *_Parents__Repr) LookupByNode(k ipld.Node) (ipld.Node, error) {
	v, err := (Parents)(nr).LookupByNode(k)
	if err != nil || v == ipld.Null {
		return v, err
	}
	return v.(Link).Representation(), nil
}
func (nr *_Parents__Repr) LookupByIndex(idx int) (ipld.Node, error) {
	v, err := (Parents)(nr).LookupByIndex(idx)
	if err != nil || v == ipld.Null {
		return v, err
	}
	return v.(Link).Representation(), nil
}
func (n _Parents__Repr) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) {
	i, err := seg.Index()
	if err != nil {
		return nil, ipld.ErrInvalidSegmentForList{TypeName: "chaintypes.Parents.Repr", TroubleSegment: seg, Reason: err}
	}
	return n.LookupByIndex(i)
}
func (_Parents__Repr) MapIterator() ipld.MapIterator {
	return nil
}
func (nr *_Parents__Repr) ListIterator() ipld.ListIterator {
	return &_Parents__ReprListItr{(Parents)(nr), 0}
}

type _Parents__ReprListItr _Parents__ListItr

func (itr *_Parents__ReprListItr) Next() (idx int, v ipld.Node, err error) {
	idx, v, err = (*_Parents__ListItr)(itr).Next()
	if err != nil || v == ipld.Null {
		return
	}
	return idx, v.(Link).Representation(), nil
}
func (itr *_Parents__ReprListItr) Done() bool {
	return (*_Parents__ListItr)(itr).Done()
}

func (rn *_Parents__Repr) Length() int {
	return len(rn.x)
}
func (_Parents__Repr) IsAbsent() bool {
	return false
}
func (_Parents__Repr) IsNull() bool {
	return false
}
func (_Parents__Repr) AsBool() (bool, error) {
	return mixins.List{"chaintypes.Parents.Repr"}.AsBool()
}
func (_Parents__Repr) AsInt() (int, error) {
	return mixins.List{"chaintypes.Parents.Repr"}.AsInt()
}
func (_Parents__Repr) AsFloat() (float64, error) {
	return mixins.List{"chaintypes.Parents.Repr"}.AsFloat()
}
func (_Parents__Repr) AsString() (string, error) {
	return mixins.List{"chaintypes.Parents.Repr"}.AsString()
}
func (_Parents__Repr) AsBytes() ([]byte, error) {
	return mixins.List{"chaintypes.Parents.Repr"}.AsBytes()
}
func (_Parents__Repr) AsLink() (ipld.Link, error) {
	return mixins.List{"chaintypes.Parents.Repr"}.AsLink()
}
func (_Parents__Repr) Prototype() ipld.NodePrototype {
	return _Parents__ReprPrototype{}
}

type _Parents__ReprPrototype struct{}

func (_Parents__ReprPrototype) NewBuilder() ipld.NodeBuilder {
	var nb _Parents__ReprBuilder
	nb.Reset()
	return &nb
}

type _Parents__ReprBuilder struct {
	_Parents__ReprAssembler
}

func (nb *_Parents__ReprBuilder) Build() ipld.Node {
	if *nb.m != schema.Maybe_Value {
		panic("invalid state: cannot call Build on an assembler that's not finished")
	}
	return nb.w
}
func (nb *_Parents__ReprBuilder) Reset() {
	var w _Parents
	var m schema.Maybe
	*nb = _Parents__ReprBuilder{_Parents__ReprAssembler{w: &w, m: &m}}
}

type _Parents__ReprAssembler struct {
	w     *_Parents
	m     *schema.Maybe
	state laState

	cm schema.Maybe
	va _Link__ReprAssembler
}

func (na *_Parents__ReprAssembler) reset() {
	na.state = laState_initial
	na.va.reset()
}
func (_Parents__ReprAssembler) BeginMap(sizeHint int) (ipld.MapAssembler, error) {
	return mixins.ListAssembler{"chaintypes.Parents.Repr"}.BeginMap(0)
}
func (na *_Parents__ReprAssembler) BeginList(sizeHint int) (ipld.ListAssembler, error) {
	switch *na.m {
	case schema.Maybe_Value, schema.Maybe_Null:
		panic("invalid state: cannot assign into assembler that's already finished")
	case midvalue:
		panic("invalid state: it makes no sense to 'begin' twice on the same assembler!")
	}
	*na.m = midvalue
	if sizeHint < 0 {
		sizeHint = 0
	}
	if na.w == nil {
		na.w = &_Parents{}
	}
	if sizeHint > 0 {
		na.w.x = make([]_Link, 0, sizeHint)
	}
	return na, nil
}
func (na *_Parents__ReprAssembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.ListAssembler{"chaintypes.Parents.Repr.Repr"}.AssignNull()
	case schema.Maybe_Value, schema.Maybe_Null:
		panic("invalid state: cannot assign into assembler that's already finished")
	case midvalue:
		panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!")
	}
	panic("unreachable")
}
func (_Parents__ReprAssembler) AssignBool(bool) error {
	return mixins.ListAssembler{"chaintypes.Parents.Repr"}.AssignBool(false)
}
func (_Parents__ReprAssembler) AssignInt(int) error {
	return mixins.ListAssembler{"chaintypes.Parents.Repr"}.AssignInt(0)
}
func (_Parents__ReprAssembler) AssignFloat(float64) error {
	return mixins.ListAssembler{"chaintypes.Parents.Repr"}.AssignFloat(0)
}
func (_Parents__ReprAssembler) AssignString(string) error {
	return mixins.ListAssembler{"chaintypes.Parents.Repr"}.AssignString("")
}
func (_Parents__ReprAssembler) AssignBytes([]byte) error {
	return mixins.ListAssembler{"chaintypes.Parents.Repr"}.AssignBytes(nil)
}
func (_Parents__ReprAssembler) AssignLink(ipld.Link) error {
	return mixins.ListAssembler{"chaintypes.Parents.Repr"}.AssignLink(nil)
}
func (na *_Parents__ReprAssembler) AssignNode(v ipld.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_Parents); ok {
		switch *na.m {
		case schema.Maybe_Value, schema.Maybe_Null:
			panic("invalid state: cannot assign into assembler that's already finished")
		case midvalue:
			panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!")
		}
		if na.w == nil {
			na.w = v2
			*na.m = schema.Maybe_Value
			return nil
		}
		*na.w = *v2
		*na.m = schema.Maybe_Value
		return nil
	}
	if v.ReprKind() != ipld.ReprKind_List {
		return ipld.ErrWrongKind{TypeName: "chaintypes.Parents.Repr", MethodName: "AssignNode", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: v.ReprKind()}
	}
	itr := v.ListIterator()
	for !itr.Done() {
		_, v, err := itr.Next()
		if err != nil {
			return err
		}
		if err := na.AssembleValue().AssignNode(v); err != nil {
			return err
		}
	}
	return na.Finish()
}
func (_Parents__ReprAssembler) Prototype() ipld.NodePrototype {
	return _Parents__ReprPrototype{}
}
func (la *_Parents__ReprAssembler) valueFinishTidy() bool {
	switch la.cm {
	case schema.Maybe_Value:
		la.va.w = nil
		la.cm = schema.Maybe_Absent
		la.state = laState_initial
		la.va.reset()
		return true
	default:
		return false
	}
}
func (la *_Parents__ReprAssembler) AssembleValue() ipld.NodeAssembler {
	switch la.state {
	case laState_initial:

	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value")
		} 
	case laState_finished:
		panic("invalid state: AssembleValue cannot be called on an assembler that's already finished")
	}
	la.w.x = append(la.w.x, _Link{})
	la.state = laState_midValue
	row := &la.w.x[len(la.w.x)-1]
	la.va.w = row
	la.va.m = &la.cm
	return &la.va
}
func (la *_Parents__ReprAssembler) Finish() error {
	switch la.state {
	case laState_initial:

	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: Finish cannot be called when in the middle of assembling a value")
		} 
	case laState_finished:
		panic("invalid state: Finish cannot be called on an assembler that's already finished")
	}
	la.state = laState_finished
	*la.m = schema.Maybe_Value
	return nil
}
func (la *_Parents__ReprAssembler) ValuePrototype(_ int) ipld.NodePrototype {
	return _Link__ReprPrototype{}
}
package chaintypes

// Code generated by go-ipld-prime gengo.  DO NOT EDIT.

import (
	ipld "github.com/ipld/go-ipld-prime"
	"github.com/ipld/go-ipld-prime/node/mixins"
	"github.com/ipld/go-ipld-prime/schema"
)

type _Parents struct {
	x []_Link
}
type Parents = *_Parents
type _Parents__Maybe struct {
	m schema.Maybe
	v Parents
}
type MaybeParents = *_Parents__Maybe

func (m MaybeParents) IsNull() bool {
	return m.m == schema.Maybe_Null
}
func (m MaybeParents) IsAbsent() bool {
	return m.m == schema.Maybe_Absent
}
func (m MaybeParents) Exists() bool {
	return m.m == schema.Maybe_Value
}
func (m MaybeParents) AsNode() ipld.Node {
	switch m.m {
	case schema.Maybe_Absent:
		return ipld.Absent
	case schema.Maybe_Null:
		return ipld.Null
	case schema.Maybe_Value:
		return m.v
	default:
		panic("unreachable")
	}
}
func (m MaybeParents) Must() Parents {
	if !m.Exists() {
		panic("unbox of a maybe rejected")
	}
	return m.v
}

var _ ipld.Node = (Parents)(&_Parents{})
var _ schema.TypedNode = (Parents)(&_Parents{})

func (Parents) ReprKind() ipld.ReprKind {
	return ipld.ReprKind_List
}
func (Parents) LookupByString(string) (ipld.Node, error) {
	return mixins.List{"chaintypes.Parents"}.LookupByString("")
}
func (n Parents) LookupByNode(k ipld.Node) (ipld.Node, error) {
	idx, err := k.AsInt()
	if err != nil {
		return nil, err
	}
	return n.LookupByIndex(idx)
}
func (n Parents) LookupByIndex(idx int) (ipld.Node, error) {
	if n.Length() <= idx {
		return nil, ipld.ErrNotExists{ipld.PathSegmentOfInt(idx)}
	}
	v := &n.x[idx]
	return v, nil
}
func (n Parents) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) {
	i, err := seg.Index()
	if err != nil {
		return nil, ipld.ErrInvalidSegmentForList{TypeName: "chaintypes.Parents", TroubleSegment: seg, Reason: err}
	}
	return n.LookupByIndex(i)
}
func (Parents) MapIterator() ipld.MapIterator {
	return nil
}
func (n Parents) ListIterator() ipld.ListIterator {
	return &_Parents__ListItr{n, 0}
}

type _Parents__ListItr struct {
	n   Parents
	idx int
}

func (itr *_Parents__ListItr) Next() (idx int, v ipld.Node, _ error) {
	if itr.idx >= len(itr.n.x) {
		return -1, nil, ipld.ErrIteratorOverread{}
	}
	idx = itr.idx
	x := &itr.n.x[itr.idx]
	v = x
	itr.idx++
	return
}
func (itr *_Parents__ListItr) Done() bool {
	return itr.idx >= len(itr.n.x)
}

func (n Parents) Length() int {
	return len(n.x)
}
func (Parents) IsAbsent() bool {
	return false
}
func (Parents) IsNull() bool {
	return false
}
func (Parents) AsBool() (bool, error) {
	return mixins.List{"chaintypes.Parents"}.AsBool()
}
func (Parents) AsInt() (int, error) {
	return mixins.List{"chaintypes.Parents"}.AsInt()
}
func (Parents) AsFloat() (float64, error) {
	return mixins.List{"chaintypes.Parents"}.AsFloat()
}
func (Parents) AsString() (string, error) {
	return mixins.List{"chaintypes.Parents"}.AsString()
}
func (Parents) AsBytes() ([]byte, error) {
	return mixins.List{"chaintypes.Parents"}.AsBytes()
}
func (Parents) AsLink() (ipld.Link, error) {
	return mixins.List{"chaintypes.Parents"}.AsLink()
}
func (Parents) Prototype() ipld.NodePrototype {
	return _Parents__Prototype{}
}

type _Parents__Prototype struct{}

func (_Parents__Prototype) NewBuilder() ipld.NodeBuilder {
	var nb _Parents__Builder
	nb.Reset()
	return &nb
}

type _Parents__Builder struct {
	_Parents__Assembler
}

func (nb *_Parents__Builder) Build() ipld.Node {
	if *nb.m != schema.Maybe_Value {
		panic("invalid state: cannot call Build on an assembler that's not finished")
	}
	return nb.w
}
func (nb *_Parents__Builder) Reset() {
	var w _Parents
	var m schema.Maybe
	*nb = _Parents__Builder{_Parents__Assembler{w: &w, m: &m}}
}

type _Parents__Assembler struct {
	w     *_Parents
	m     *schema.Maybe
	state laState

	cm schema.Maybe
	va _Link__Assembler
}

func (na *_Parents__Assembler) reset() {
	na.state = laState_initial
	na.va.reset()
}
func (_Parents__Assembler) BeginMap(sizeHint int) (ipld.MapAssembler, error) {
	return mixins.ListAssembler{"chaintypes.Parents"}.BeginMap(0)
}
func (na *_Parents__Assembler) BeginList(sizeHint int) (ipld.ListAssembler, error) {
	switch *na.m {
	case schema.Maybe_Value, schema.Maybe_Null:
		panic("invalid state: cannot assign into assembler that's already finished")
	case midvalue:
		panic("invalid state: it makes no sense to 'begin' twice on the same assembler!")
	}
	*na.m = midvalue
	if sizeHint < 0 {
		sizeHint = 0
	}
	if na.w == nil {
		na.w = &_Parents{}
	}
	if sizeHint > 0 {
		na.w.x = make([]_Link, 0, sizeHint)
	}
	return na, nil
}
func (na *_Parents__Assembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.ListAssembler{"chaintypes.Parents"}.AssignNull()
	case schema.Maybe_Value, schema.Maybe_Null:
		panic("invalid state: cannot assign into assembler that's already finished")
	case midvalue:
		panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!")
	}
	panic("unreachable")
}
func (_Parents__Assembler) AssignBool(bool) error {
	return mixins.ListAssembler{"chaintypes.Parents"}.AssignBool(false)
}
func (_Parents__Assembler) AssignInt(int) error {
	return mixins.ListAssembler{"chaintypes.Parents"}.AssignInt(0)
}
func (_Parents__Assembler) AssignFloat(float64) error {
	return mixins.ListAssembler{"chaintypes.Parents"}.AssignFloat(0)
}
func (_Parents__Assembler) AssignString(string) error {
	return mixins.ListAssembler{"chaintypes.Parents"}.AssignString("")
}
func (_Parents__Assembler) AssignBytes([]byte) error {
	return mixins.ListAssembler{"chaintypes.Parents"}.AssignBytes(nil)
}
func (_Parents__Assembler) AssignLink(ipld.Link) error {
	return mixins.ListAssembler{"chaintypes.Parents"}.AssignLink(nil)
}
func (na *_Parents__Assembler) AssignNode(v ipld.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_Parents); ok {
		switch *na.m {
		case schema.Maybe_Value, schema.Maybe_Null:
			panic("invalid state: cannot assign into assembler that's already finished")
		case midvalue:
			panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!")
		}
		if na.w == nil {
			na.w = v2
			*na.m = schema.Maybe_Value
			return nil
		}
		*na.w = *v2
		*na.m = schema.Maybe_Value
		return nil
	}
	if v.ReprKind() != ipld.ReprKind_List {
		return ipld.ErrWrongKind{TypeName: "chaintypes.Parents", MethodName: "AssignNode", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: v.ReprKind()}
	}
	itr := v.ListIterator()
	for !itr.Done() {
		_, v, err := itr.Next()
		if err != nil {
			return err
		}
		if err := na.AssembleValue().AssignNode(v); err != nil {
			return err
		}
	}
	return na.Finish()
}
func (_Parents__Assembler) Prototype() ipld.NodePrototype {
	return _Parents__Prototype{}
}
func (la *_Parents__Assembler) valueFinishTidy() bool {
	switch la.cm {
	case schema.Maybe_Value:
		la.va.w = nil
		la.cm = schema.Maybe_Absent
		la.state = laState_initial
		la.va.reset()
		return true
	default:
		return false
	}
}
func (la *_Parents__Assembler) AssembleValue() ipld.NodeAssembler {
	switch la.state {
	case laState_initial:
		// carry on
	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value")
		} // if tidy success: carry on
	case laState_finished:
		panic("invalid state: AssembleValue cannot be called on an assembler that's already finished")
	}
	la.w.x = append(la.w.x, _Link{})
	la.state = laState_midValue
	row := &la.w.x[len(la.w.x)-1]
	la.va.w = row
	la.va.m = &la.cm
	return &la.va
}
func (la *_Parents__Assembler) Finish() error {
	switch la.state {
	case laState_initial:
		// carry on
	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: Finish cannot be called when in the middle of assembling a value")
		} // if tidy success: carry on
	case laState_finished:
		panic("invalid state: Finish cannot be called on an assembler that's already finished")
	}
	la.state = laState_finished
	*la.m = schema.Maybe_Value
	return nil
}
func (la *_Parents__Assembler) ValuePrototype(_ int) ipld.NodePrototype {
	return _Link__Prototype{}
}
func (Parents) Type() schema.Type {
	return nil /*TODO:typelit*/
}
func (n Parents) Representation() ipld.Node {
	return (*_Parents__Repr)(n)
}

type _Parents__Repr _Parents

var _ ipld.Node = &_Parents__Repr{}

func (_Parents__Repr) ReprKind() ipld.ReprKind {
	return ipld.ReprKind_List
}
func (_Parents__Repr) LookupByString(string) (ipld.Node, error) {
	return mixins.List{"chaintypes.Parents.Repr"}.LookupByString("")
}
func (nr *_Parents__Repr) LookupByNode(k ipld.Node) (ipld.Node, error) {
	v, err := (Parents)(nr).LookupByNode(k)
	if err != nil || v == ipld.Null {
		return v, err
	}
	return v.(Link).Representation(), nil
}
func (nr *_Parents__Repr) LookupByIndex(idx int) (ipld.Node, error) {
	v, err := (Parents)(nr).LookupByIndex(idx)
	if err != nil || v == ipld.Null {
		return v, err
	}
	return v.(Link).Representation(), nil
}
func (n _Parents__Repr) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) {
	i, err := seg.Index()
	if err != nil {
		return nil, ipld.ErrInvalidSegmentForList{TypeName: "chaintypes.Parents.Repr", TroubleSegment: seg, Reason: err}
	}
	return n.LookupByIndex(i)
}
func (_Parents__Repr) MapIterator() ipld.MapIterator {
	return nil
}
func (nr *_Parents__Repr) ListIterator() ipld.ListIterator {
	return &_Parents__ReprListItr{(Parents)(nr), 0}
}

type _Parents__ReprListItr _Parents__ListItr

func (itr *_Parents__ReprListItr) Next() (idx int, v ipld.Node, err error) {
	idx, v, err = (*_Parents__ListItr)(itr).Next()
	if err != nil || v == ipld.Null {
		return
	}
	return idx, v.(Link).Representation(), nil
}
func (itr *_Parents__ReprListItr) Done() bool {
	return (*_Parents__ListItr)(itr).Done()
}

func (rn *_Parents__Repr) Length() int {
	return len(rn.x)
}
func (_Parents__Repr) IsAbsent() bool {
	return false
}
func (_Parents__Repr) IsNull() bool {
	return false
}
func (_Parents__Repr) AsBool() (bool, error) {
	return mixins.List{"chaintypes.Parents.Repr"}.AsBool()
}
func (_Parents__Repr) AsInt() (int, error) {
	return mixins.List{"chaintypes.Parents.Repr"}.AsInt()
}
func (_Parents__Repr) AsFloat() (float64, error) {
	return mixins.List{"chaintypes.Parents.Repr"}.AsFloat()
}
func (_Parents__Repr) AsString() (string, error) {
	return mixins.List{"chaintypes.Parents.Repr"}.AsString()
}
func (_Parents__Repr) AsBytes() ([]byte, error) {
	return mixins.List{"chaintypes.Parents.Repr"}.AsBytes()
}
func (_Parents__Repr) AsLink() (ipld.Link, error) {
	return mixins.List{"chaintypes.Parents.Repr"}.AsLink()
}
func (_Parents__Repr) Prototype() ipld.NodePrototype {
	return _Parents__ReprPrototype{}
}

type _Parents__ReprPrototype struct{}

func (_Parents__ReprPrototype) NewBuilder() ipld.NodeBuilder {
	var nb _Parents__ReprBuilder
	nb.Reset()
	return &nb
}

type _Parents__ReprBuilder struct {
	_Parents__ReprAssembler
}

func (nb *_Parents__ReprBuilder) Build() ipld.Node {
	if *nb.m != schema.Maybe_Value {
		panic("invalid state: cannot call Build on an assembler that's not finished")
	}
	return nb.w
}
func (nb *_Parents__ReprBuilder) Reset() {
	var w _Parents
	var m schema.Maybe
	*nb = _Parents__ReprBuilder{_Parents__ReprAssembler{w: &w, m: &m}}
}

type _Parents__ReprAssembler struct {
	w     *_Parents
	m     *schema.Maybe
	state laState

	cm schema.Maybe
	va _Link__ReprAssembler
}

func (na *_Parents__ReprAssembler) reset() {
	na.state = laState_initial
	na.va.reset()
}
func (_Parents__ReprAssembler) BeginMap(sizeHint int) (ipld.MapAssembler, error) {
	return mixins.ListAssembler{"chaintypes.Parents.Repr"}.BeginMap(0)
}
func (na *_Parents__ReprAssembler) BeginList(sizeHint int) (ipld.ListAssembler, error) {
	switch *na.m {
	case schema.Maybe_Value, schema.Maybe_Null:
		panic("invalid state: cannot assign into assembler that's already finished")
	case midvalue:
		panic("invalid state: it makes no sense to 'begin' twice on the same assembler!")
	}
	*na.m = midvalue
	if sizeHint < 0 {
		sizeHint = 0
	}
	if na.w == nil {
		na.w = &_Parents{}
	}
	if sizeHint > 0 {
		na.w.x = make([]_Link, 0, sizeHint)
	}
	return na, nil
}
func (na *_Parents__ReprAssembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.ListAssembler{"chaintypes.Parents.Repr.Repr"}.AssignNull()
	case schema.Maybe_Value, schema.Maybe_Null:
		panic("invalid state: cannot assign into assembler that's already finished")
	case midvalue:
		panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!")
	}
	panic("unreachable")
}
func (_Parents__ReprAssembler) AssignBool(bool) error {
	return mixins.ListAssembler{"chaintypes.Parents.Repr"}.AssignBool(false)
}
func (_Parents__ReprAssembler) AssignInt(int) error {
	return mixins.ListAssembler{"chaintypes.Parents.Repr"}.AssignInt(0)
}
func (_Parents__ReprAssembler) AssignFloat(float64) error {
	return mixins.ListAssembler{"chaintypes.Parents.Repr"}.AssignFloat(0)
}
func (_Parents__ReprAssembler) AssignString(string) error {
	return mixins.ListAssembler{"chaintypes.Parents.Repr"}.AssignString("")
}
func (_Parents__ReprAssembler) AssignBytes([]byte) error {
	return mixins.ListAssembler{"chaintypes.Parents.Repr"}.AssignBytes(nil)
}
func (_Parents__ReprAssembler) AssignLink(ipld.Link) error {
	return mixins.ListAssembler{"chaintypes.Parents.Repr"}.AssignLink(nil)
}
func (na *_Parents__ReprAssembler) AssignNode(v ipld.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_Parents); ok {
		switch *na.m {
		case schema.Maybe_Value, schema.Maybe_Null:
			panic("invalid state: cannot assign into assembler that's already finished")
		case midvalue:
			panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!")
		}
		if na.w == nil {
			na.w = v2
			*na.m = schema.Maybe_Value
			return nil
		}
		*na.w = *v2
		*na.m = schema.Maybe_Value
		return nil
	}
	if v.ReprKind() != ipld.ReprKind_List {
		return ipld.ErrWrongKind{TypeName: "chaintypes.Parents.Repr", MethodName: "AssignNode", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: v.ReprKind()}
	}
	itr := v.ListIterator()
	for !itr.Done() {
		_, v, err := itr.Next()
		if err != nil {
			return err
		}
		if err := na.AssembleValue().AssignNode(v); err != nil {
			return err
		}
	}
	return na.Finish()
}
func (_Parents__ReprAssembler) Prototype() ipld.NodePrototype {
	return _Parents__ReprPrototype{}
}
func (la *_Parents__ReprAssembler) valueFinishTidy() bool {
	switch la.cm {
	case schema.Maybe_Value:
		la.va.w = nil
		la.cm = schema.Maybe_Absent
		la.state = laState_initial
		la.va.reset()
		return true
	default:
		return false
	}
}
func (la *_Parents__ReprAssembler) AssembleValue() ipld.NodeAssembler {
	switch la.state {
	case laState_initial:
		// carry on
	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value")
		} // if tidy success: carry on
	case laState_finished:
		panic("invalid state: AssembleValue cannot be called on an assembler that's already finished")
	}
	la.w.x = append(la.w.x, _Link{})
	la.state = laState_midValue
	row := &la.w.x[len(la.w.x)-1]
	la.va.w = row
	la.va.m = &la.cm
	return &la.va
}
func (la *_Parents__ReprAssembler) Finish() error {
	switch la.state {
	case laState_initial:
		// carry on
	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: Finish cannot be called when in the middle of assembling a value")
		} // if tidy success: carry on
	case laState_finished:
		panic("invalid state: Finish cannot be called on an assembler that's already finished")
	}
	la.state = laState_finished
	*la.m = schema.Maybe_Value
	return nil
}
func (la *_Parents__ReprAssembler) ValuePrototype(_ int) ipld.NodePrototype {
	return _Link__ReprPrototype{}
}
