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

type ColorListEntries struct {
	Color types.String `tfsdk:"color"`
}

func (data ColorList) getType() string {
	return "color"
}

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

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