
func (v {{.Name}}Value) From{{.AssocExtType.ToPascalCase}}(ctx context.Context, apiObject {{.AssocExtType.Type}}) ({{.Name}}Value, diag.Diagnostics) {
var diags diag.Diagnostics

if apiObject == nil {
return New{{.Name}}ValueNull(), diags
}
{{- range $key, $value := .FromFuncs}}
{{- if $value.AssocExtType}}

{{$key.ToCamelCase}}Val, d := {{$key.ToPascalCase}}Value{}.From{{$value.AssocExtType.ToPascalCase}}(ctx, apiObject.{{$key.ToPascalCase}})

diags.Append(d...)

if diags.HasError() {
return New{{$.Name}}ValueUnknown(), diags
}
{{- else if $value.CollectionType.ElementType}}

{{$key.ToCamelCase}}Val, d := {{$value.CollectionType.TypeValueFrom}}(ctx, {{$value.CollectionType.ElementType}}, apiObject.{{$key.ToPascalCase}})

diags.Append(d...)

if diags.HasError() {
return New{{$.Name}}ValueUnknown(), diags
}
{{- else if $value.ObjectType}}

{{$key.ToCamelCase}}Val, d := basetypes.NewObjectValue(
map[string]attr.Type{
{{- range $objectTypeKey, $objectTypeVal := $value.ObjectType}}
"{{$objectTypeKey}}": {{$objectTypeVal.Type}},
{{- end}}
}, map[string]attr.Value{
{{- range $objectTypeKey, $objectTypeVal := $value.ObjectType}}
"{{$objectTypeKey}}": types.{{$objectTypeVal.FromFunc}}(apiObject.{{$key.ToPascalCase}}.{{$objectTypeKey.ToPascalCase}}),
{{- end}}
})

diags.Append(d...)

if diags.HasError() {
return New{{$.Name}}ValueUnknown(), diags
}
{{- end}}
{{- end}}

return {{.Name}}Value{
{{- range $key, $value := .FromFuncs}}
{{- if $value.AssocExtType}}
{{$key.ToPrefixPascalCase $.Name}}: {{$key.ToCamelCase}}Val,
{{- else if $value.Default}}
{{$key.ToPrefixPascalCase $.Name}}: types.{{$value.Default}}(apiObject.{{$key.ToPascalCase}}),
{{- else if $value.CollectionType.ElementType}}
{{$key.ToPrefixPascalCase $.Name}}: {{$key.ToCamelCase}}Val,
{{- else if $value.ObjectType}}
{{$key.ToPrefixPascalCase $.Name}}: {{$key.ToCamelCase}}Val,
{{- end}}
{{- end}}
state: attr.ValueStateKnown,
}, diags
}
