// Code generated by eevee. DO NOT EDIT!

package entity

import (
	"go.knocknote.io/rapidash"
	"golang.org/x/xerrors"
)

type World struct {
	ID   uint64 `json:"id"`
	Name string `json:"name"`
}

type Worlds []*World

func (e Worlds) IDs() []uint64 {
	values := make([]uint64, 0, len(e))
	for _, value := range e {
		values = append(values, value.ID)
	}
	return values
}

func (e Worlds) Names() []string {
	values := make([]string, 0, len(e))
	for _, value := range e {
		values = append(values, value.Name)
	}
	return values
}

func (e *World) Struct() *rapidash.Struct {
	return rapidash.NewStruct("worlds").
		FieldUint64("id").
		FieldString("name")
}

func (e *World) EncodeRapidash(enc rapidash.Encoder) error {
	if e.ID != 0 {
		enc.Uint64("id", e.ID)
	}
	enc.String("name", e.Name)
	if err := enc.Error(); err != nil {
		return xerrors.Errorf("failed to encode: %w", err)
	}
	return nil
}

func (e *Worlds) EncodeRapidash(enc rapidash.Encoder) error {
	for _, v := range *e {
		if err := v.EncodeRapidash(enc.New()); err != nil {
			return xerrors.Errorf("failed to encode: %w", err)
		}
	}
	return nil
}

func (e *World) DecodeRapidash(dec rapidash.Decoder) error {
	e.ID = dec.Uint64("id")
	e.Name = dec.String("name")
	if err := dec.Error(); err != nil {
		return xerrors.Errorf("failed to decode: %w", err)
	}
	return nil
}

func (e *Worlds) DecodeRapidash(dec rapidash.Decoder) error {
	decLen := dec.Len()
	values := make(Worlds, decLen)
	for i := 0; i < decLen; i++ {
		var v World
		if err := v.DecodeRapidash(dec.At(i)); err != nil {
			return xerrors.Errorf("failed to decode: %w", err)
		}
		values[i] = &v
	}
	*e = values
	return nil
}
