// Code generated by "gen/generator.go"; DO NOT EDIT.

package provider

import (
	"context"

	"github.com/hashicorp/terraform-plugin-framework/types"
	"github.com/tidwall/gjson"
	"github.com/tidwall/sjson"
)

type StandardCommunityList struct {
	Id      types.String                   `tfsdk:"id"`
	Version types.Int64                    `tfsdk:"version"`
	Name    types.String                   `tfsdk:"name"`
	Entries []StandardCommunityListEntries `tfsdk:"entries"`
}

type StandardCommunityListEntries struct {
	Community types.String `tfsdk:"community"`
}

func (data StandardCommunityList) getType() string {
	return "community"
}

func (data StandardCommunityList) toBody(ctx context.Context) string {
	body, _ := sjson.Set("", "description", "Desc Not Required")
	body, _ = sjson.Set(body, "name", data.Name.ValueString())
	body, _ = sjson.Set(body, "type", "community")
	if len(data.Entries) > 0 {
		body, _ = sjson.Set(body, "entries", []interface{}{})
		for _, item := range data.Entries {
			itemBody := ""
			if !item.Community.IsNull() {
				itemBody, _ = sjson.Set(itemBody, "community", item.Community.ValueString())
			}
			body, _ = sjson.SetRaw(body, "entries.-1", itemBody)
		}
	}
	return body
}

func (data *StandardCommunityList) fromBody(ctx context.Context, res gjson.Result) {
	if value := res.Get("name"); value.Exists() {
		data.Name = types.StringValue(value.String())
	} else {
		data.Name = types.StringNull()
	}
	if value := res.Get("entries"); value.Exists() {
		data.Entries = make([]StandardCommunityListEntries, 0)
		value.ForEach(func(k, v gjson.Result) bool {
			item := StandardCommunityListEntries{}
			if cValue := v.Get("community"); cValue.Exists() {
				item.Community = types.StringValue(cValue.String())
			} else {
				item.Community = types.StringNull()
			}
			data.Entries = append(data.Entries, item)
			return true
		})
	}
}
