// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.

package provider

import (
	"encoding/json"
	"github.com/airbytehq/terraform-provider-airbyte/internal/sdk/models/shared"
	"github.com/hashicorp/terraform-plugin-framework/types"
)

func (r *DeclarativeSourceDefinitionResourceModel) ToSharedCreateDeclarativeSourceDefinitionRequest() *shared.CreateDeclarativeSourceDefinitionRequest {
	var name string
	name = r.Name.ValueString()

	var manifest interface{}
	_ = json.Unmarshal([]byte(r.Manifest.ValueString()), &manifest)
	out := shared.CreateDeclarativeSourceDefinitionRequest{
		Name:     name,
		Manifest: manifest,
	}
	return &out
}

func (r *DeclarativeSourceDefinitionResourceModel) RefreshFromSharedDeclarativeSourceDefinitionResponse(resp *shared.DeclarativeSourceDefinitionResponse) {
	if resp != nil {
		r.ID = types.StringValue(resp.ID)
		manifestResult, _ := json.Marshal(resp.Manifest)
		r.Manifest = types.StringValue(string(manifestResult))
		r.Name = types.StringValue(resp.Name)
		r.Version = types.Int64Value(resp.Version)
	}
}

func (r *DeclarativeSourceDefinitionResourceModel) ToSharedUpdateDeclarativeSourceDefinitionRequest() *shared.UpdateDeclarativeSourceDefinitionRequest {
	var manifest interface{}
	_ = json.Unmarshal([]byte(r.Manifest.ValueString()), &manifest)
	out := shared.UpdateDeclarativeSourceDefinitionRequest{
		Manifest: manifest,
	}
	return &out
}
