
// Record types
const (
{{- range $r := $.Records}}
	Rt{{$r.Type}} RecordType = "{{call $.RecordTypeString $r.Type}}"
{{- end}}
)

// Field types
const (
{{- range $f := $.Fields}}
	Ft{{$f.Type}} FieldType = "{{call $.FieldTypeString $f.Type}}"
{{- end}}
)

// The value types a field may contain
const (
{{- range $vt := $.ValueTypes}}
	Vt{{call $.Capitalize $vt}} ValueType = "{{$vt}}"
{{- end}}
)

// newValue returns a new value of the given ValueType
func newValue(vt ValueType) value {
	switch vt {
	{{- range $vt := $.ValueTypes}}
	case Vt{{call $.Capitalize $vt}}:
		return new({{$vt}})
	{{- end}}
	}

	return nil
}

var codeplugInfos = []*CodeplugInfo{
{{- range $c := $.Codeplugs}}
	&cp{{call $.Capitalize $c.Type}},
{{- end}}
}

{{- range $c := $.Codeplugs}}

var cp{{call $.Capitalize $c.Type}} = CodeplugInfo{
	Type: "{{$c.Type}}",
	Models: []string{
	{{- range $name := $c.Models}}
		"{{$name}}",
	{{- end}}
	},
	Ext: "{{$c.Ext}}",
	RdtSize: {{$c.RdtSize}},
	BinSize: {{$c.BinSize}},
	BinOffset: {{$c.BinOffset}},
	RecordInfos: []*recordInfo{
	{{- range $rt := $c.RecordTypes}}
		&ri{{$rt}},
	{{- end}}
	},
}
{{- end}}

{{- range $r := $.Records}}

var ri{{$r.Type}} = recordInfo{
	rType: Rt{{$r.Type}},
	typeName: "{{$r.TypeName}}",
	max: {{$r.Max}},
	offset: {{$r.Offset}},
	size: {{$r.Size}},
{{- if $r.DelDescs}}
	delDescs: []delDesc{
	{{- range $d := $r.DelDescs}}
		delDesc{
			offset: {{$d.Offset}},
			size: {{$d.Size}},
			value: {{$d.Value}},
		},
	{{- end}}
	},
{{- end}}
	fieldInfos: []*fieldInfo{
	{{- range $ft := $r.FieldTypes}}
		&fi{{$ft}},
	{{- end}}
	},
}
{{ end}}

{{- range $f := $.Fields}}

var fi{{$f.Type}} = fieldInfo{
	fType: Ft{{$f.Type}},
	typeName: "{{$f.TypeName}}",
	max: {{$f.Max}},
	bitOffset: {{$f.BitOffset}},
	bitSize: {{$f.BitSize}},
	valueType: Vt{{call $.Capitalize $f.ValueType}},
{{- if $f.DefaultValue}}
	defaultValue: "{{$f.DefaultValue}}",
{{- end}}
{{- if $f.Strings}}
	strings: &[]string{
	{{- range $s := $f.Strings}}
		"{{$s}}",
	{{- end}}
	},
{{- end}}
{{- if $f.Span}}{{$s := $f.Span}}
	span: &Span{
		min: {{$s.Min}},
		max: {{$s.Max}},
	{{- if $s.Scale}}
		scale: {{$s.Scale}},
	{{- end}}
	{{- if $s.Interval}}
		interval: {{$s.Interval}},
	{{- end}}
	{{- if $s.MinString}}
		minString: "{{$s.MinString}}",
	{{- end}}
	},
{{- end}}
{{- if $f.IndexedStrings}}
	indexedStrings: &[]IndexedString{
	{{- range $i := $f.IndexedStrings}}
		IndexedString{ {{$i.Index}}, "{{$i.String}}"},
	{{- end}}
	},
{{- end}}
{{- if $f.ListType}}
	listRecordType: Rt{{$f.ListType}},
{{- end}}
{{- if $f.EnablingValue}}
	enablingValue: "{{$f.EnablingValue}}",
{{- end}}
{{- if $f.Enabler}}
	enabler: Ft{{$f.Enabler}},
{{- end}}
{{- if $f.Disabler}}
	disabler: Ft{{$f.Disabler}},
{{- end}}
{{- if $f.ExtIndex}}
	extOffset: {{$f.ExtOffset}},
	extSize: {{$f.ExtSize}},
	extIndex: {{$f.ExtIndex}},
{{- end}}
}
{{- end}}
