// 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 SiteList struct {
	Id      types.String      `tfsdk:"id"`
	Version types.Int64       `tfsdk:"version"`
	Name    types.String      `tfsdk:"name"`
	Entries []SiteListEntries `tfsdk:"entries"`
}

type SiteListEntries struct {
	SiteId types.String `tfsdk:"site_id"`
}

func (data SiteList) getType() string {
	return "site"
}

func (data SiteList) 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", "site")
	if len(data.Entries) > 0 {
		body, _ = sjson.Set(body, "entries", []interface{}{})
		for _, item := range data.Entries {
			itemBody := ""
			if !item.SiteId.IsNull() {
				itemBody, _ = sjson.Set(itemBody, "siteId", item.SiteId.ValueString())
			}
			body, _ = sjson.SetRaw(body, "entries.-1", itemBody)
		}
	}
	return body
}

func (data *SiteList) 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([]SiteListEntries, 0)
		value.ForEach(func(k, v gjson.Result) bool {
			item := SiteListEntries{}
			if cValue := v.Get("siteId"); cValue.Exists() {
				item.SiteId = types.StringValue(cValue.String())
			} else {
				item.SiteId = types.StringNull()
			}
			data.Entries = append(data.Entries, item)
			return true
		})
	}
}
