
func (v {{.Name}}Value) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) {
var diags diag.Diagnostics
{{- range $key, $value := .AttributeTypes }}
{{- if eq $value "ListNested" "MapNested" "SetNested"}}
{{- $typesType := "List"}}
{{- if eq $value "MapNested"}}
{{- $typesType = "Map"}}
{{- else if eq $value "SetNested"}}
{{- $typesType = "Set"}}
{{- end}}

{{$key.ToPrefixCamelCase $.Name}} := types.{{$typesType}}ValueMust(
{{$key.ToPascalCase}}Type{
basetypes.ObjectType{
AttrTypes: {{$key.ToPascalCase}}Value{}.AttributeTypes(ctx),
},
},
v.{{$key.ToPrefixPascalCase $.Name}}.Elements(),
)

if v.{{$key.ToPrefixPascalCase $.Name}}.IsNull() {
{{$key.ToPrefixCamelCase $.Name}} = types.{{$typesType}}Null(
{{$key.ToPascalCase}}Type{
basetypes.ObjectType{
AttrTypes: {{$key.ToPascalCase}}Value{}.AttributeTypes(ctx),
},
},
)
}

if v.{{$key.ToPrefixPascalCase $.Name}}.IsUnknown() {
{{$key.ToPrefixCamelCase $.Name}} = types.{{$typesType}}Unknown(
{{$key.ToPascalCase}}Type{
basetypes.ObjectType{
AttrTypes: {{$key.ToPascalCase}}Value{}.AttributeTypes(ctx),
},
},
)
}
{{else if eq $value "SingleNested"}}

var {{$key.ToCamelCase}} basetypes.ObjectValue

if v.{{$key.ToPascalCase}}.IsNull() {
{{$key.ToCamelCase}} = types.ObjectNull(
{{$key.ToPascalCase}}Value{}.AttributeTypes(ctx),
)
}

if v.{{$key.ToPascalCase}}.IsUnknown() {
{{$key.ToCamelCase}} = types.ObjectUnknown(
{{$key.ToPascalCase}}Value{}.AttributeTypes(ctx),
)
}

if !v.{{$key.ToPascalCase}}.IsNull() && !v.{{$key.ToPascalCase}}.IsUnknown() {
{{$key.ToCamelCase}} = types.ObjectValueMust(
{{$key.ToPascalCase}}Value{}.AttributeTypes(ctx),
v.{{$key.ToPascalCase}}.Attributes(),
)
}
{{end}}
{{- end}}
{{- range $key, $value := .CollectionTypes }}

{{- $typesType := "List"}}
{{- if eq $value.TypeValueFunc "types.MapValue"}}
{{- $typesType = "Map"}}
{{- else if eq $value.TypeValueFunc "types.SetValue"}}
{{- $typesType = "Set"}}
{{- end}}

var {{$key.ToCamelCase}}Val basetypes.{{$typesType}}Value
switch {
case v.{{$key.ToPrefixPascalCase $.Name}}.IsUnknown():
{{$key.ToCamelCase}}Val = types.{{$typesType}}Unknown({{$value.ElementType}})
case v.{{$key.ToPrefixPascalCase $.Name}}.IsNull():
{{$key.ToCamelCase}}Val = types.{{$typesType}}Null({{$value.ElementType}})
default:
var d diag.Diagnostics
{{$key.ToCamelCase}}Val, d = {{$value.TypeValueFunc}}({{$value.ElementType}}, v.{{$key.ToPrefixPascalCase $.Name}}.Elements())
diags.Append(d...)
}

if diags.HasError() {
return types.ObjectUnknown(map[string]attr.Type{
{{- range $attrTypeKey, $attrTypeValue := $.AttrTypes}}
"{{$attrTypeKey}}": {{$attrTypeValue}},
{{- end}}
}), diags
}
{{- end}}

{{- range $key, $value := .AttributeTypes }}
{{- if eq $value "Object"}}

{{$key.ToCamelCase}}Val, d := types.ObjectValue(v.{{$key.ToPrefixPascalCase $.Name}}.AttributeTypes(ctx), v.{{$key.ToPrefixPascalCase $.Name}}.Attributes())

diags.Append(d...)

if d.HasError() {
return types.ObjectUnknown(map[string]attr.Type{
{{- range $attrTypeKey, $attrTypeValue := $.AttrTypes}}
{{- if eq $value "Object"}}
"{{$attrTypeKey}}": basetypes.ObjectType{
AttrTypes: v.{{$key.ToPrefixPascalCase $.Name}}.AttributeTypes(ctx),
},
{{- else}}
"{{$attrTypeKey}}": {{$attrTypeValue}},
{{- end}}
{{- end}}
}), diags
}
{{- end}}
{{- end}}

attributeTypes := map[string]attr.Type{
{{- range $key, $value := .AttributeTypes }}
{{- if eq $value "Object"}}
"{{$key}}": basetypes.ObjectType{
AttrTypes: v.{{$key.ToPrefixPascalCase $.Name}}.AttributeTypes(ctx),
},
{{- else}}
"{{$key}}": {{index $.AttrTypes $key}},
{{- end}}
{{- end}}
}

if v.IsNull() {
return types.ObjectNull(attributeTypes), diags
}

if v.IsUnknown() {
return types.ObjectUnknown(attributeTypes), diags
}

objVal, diags := types.ObjectValue(
attributeTypes,
map[string]attr.Value{
{{- range $key, $value := .AttributeTypes }}
{{- if eq $value "ListNested" "MapNested" "SetNested" "SingleNested"}}
"{{$key}}": {{$key.ToPrefixCamelCase $.Name}},
{{- else if index $.CollectionTypes $key}}
"{{$key}}": {{$key.ToCamelCase}}Val,
{{- else if eq $value "Object"}}
"{{$key}}": {{$key.ToCamelCase}}Val,
{{- else}}
"{{$key}}": v.{{$key.ToPrefixPascalCase $.Name}},
{{- end}}
{{- end}}
})

return objVal, diags
}