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

type PreferredColorGroupEntries struct {
	PrimaryColorPreference   types.String `tfsdk:"primary_color_preference"`
	PrimaryPathPreference    types.String `tfsdk:"primary_path_preference"`
	SecondaryColorPreference types.String `tfsdk:"secondary_color_preference"`
	SecondaryPathPreference  types.String `tfsdk:"secondary_path_preference"`
	TertiaryColorPreference  types.String `tfsdk:"tertiary_color_preference"`
	TertiaryPathPreference   types.String `tfsdk:"tertiary_path_preference"`
}

func (data PreferredColorGroup) getType() string {
	return "preferredColorGroup"
}

func (data PreferredColorGroup) 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", "preferredColorGroup")
	if len(data.Entries) > 0 {
		body, _ = sjson.Set(body, "entries", []interface{}{})
		for _, item := range data.Entries {
			itemBody := ""
			if !item.PrimaryColorPreference.IsNull() {
				itemBody, _ = sjson.Set(itemBody, "primaryPreference.colorPreference", item.PrimaryColorPreference.ValueString())
			}
			if !item.PrimaryPathPreference.IsNull() {
				itemBody, _ = sjson.Set(itemBody, "primaryPreference.pathPreference", item.PrimaryPathPreference.ValueString())
			}
			if !item.SecondaryColorPreference.IsNull() {
				itemBody, _ = sjson.Set(itemBody, "secondaryPreference.colorPreference", item.SecondaryColorPreference.ValueString())
			}
			if !item.SecondaryPathPreference.IsNull() {
				itemBody, _ = sjson.Set(itemBody, "secondaryPreference.pathPreference", item.SecondaryPathPreference.ValueString())
			}
			if !item.TertiaryColorPreference.IsNull() {
				itemBody, _ = sjson.Set(itemBody, "tertiaryPreference.colorPreference", item.TertiaryColorPreference.ValueString())
			}
			if !item.TertiaryPathPreference.IsNull() {
				itemBody, _ = sjson.Set(itemBody, "tertiaryPreference.pathPreference", item.TertiaryPathPreference.ValueString())
			}
			body, _ = sjson.SetRaw(body, "entries.-1", itemBody)
		}
	}
	return body
}

func (data *PreferredColorGroup) 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([]PreferredColorGroupEntries, 0)
		value.ForEach(func(k, v gjson.Result) bool {
			item := PreferredColorGroupEntries{}
			if cValue := v.Get("primaryPreference.colorPreference"); cValue.Exists() {
				item.PrimaryColorPreference = types.StringValue(cValue.String())
			} else {
				item.PrimaryColorPreference = types.StringNull()
			}
			if cValue := v.Get("primaryPreference.pathPreference"); cValue.Exists() {
				item.PrimaryPathPreference = types.StringValue(cValue.String())
			} else {
				item.PrimaryPathPreference = types.StringNull()
			}
			if cValue := v.Get("secondaryPreference.colorPreference"); cValue.Exists() {
				item.SecondaryColorPreference = types.StringValue(cValue.String())
			} else {
				item.SecondaryColorPreference = types.StringNull()
			}
			if cValue := v.Get("secondaryPreference.pathPreference"); cValue.Exists() {
				item.SecondaryPathPreference = types.StringValue(cValue.String())
			} else {
				item.SecondaryPathPreference = types.StringNull()
			}
			if cValue := v.Get("tertiaryPreference.colorPreference"); cValue.Exists() {
				item.TertiaryColorPreference = types.StringValue(cValue.String())
			} else {
				item.TertiaryColorPreference = types.StringNull()
			}
			if cValue := v.Get("tertiaryPreference.pathPreference"); cValue.Exists() {
				item.TertiaryPathPreference = types.StringValue(cValue.String())
			} else {
				item.TertiaryPathPreference = types.StringNull()
			}
			data.Entries = append(data.Entries, item)
			return true
		})
	}
}
