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

package provider

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

func (r *SourceDefinitionResourceModel) ToSharedCreateDefinitionRequest() *shared.CreateDefinitionRequest {
	var name string
	name = r.Name.ValueString()

	var dockerRepository string
	dockerRepository = r.DockerRepository.ValueString()

	var dockerImageTag string
	dockerImageTag = r.DockerImageTag.ValueString()

	documentationURL := new(string)
	if !r.DocumentationURL.IsUnknown() && !r.DocumentationURL.IsNull() {
		*documentationURL = r.DocumentationURL.ValueString()
	} else {
		documentationURL = nil
	}
	out := shared.CreateDefinitionRequest{
		Name:             name,
		DockerRepository: dockerRepository,
		DockerImageTag:   dockerImageTag,
		DocumentationURL: documentationURL,
	}
	return &out
}

func (r *SourceDefinitionResourceModel) RefreshFromSharedDefinitionResponse(resp *shared.DefinitionResponse) {
	if resp != nil {
		r.DockerImageTag = types.StringValue(resp.DockerImageTag)
		r.DockerRepository = types.StringValue(resp.DockerRepository)
		r.DocumentationURL = types.StringPointerValue(resp.DocumentationURL)
		r.ID = types.StringValue(resp.ID)
		r.Name = types.StringValue(resp.Name)
	}
}

func (r *SourceDefinitionResourceModel) ToSharedUpdateDefinitionRequest() *shared.UpdateDefinitionRequest {
	var name string
	name = r.Name.ValueString()

	var dockerImageTag string
	dockerImageTag = r.DockerImageTag.ValueString()

	out := shared.UpdateDefinitionRequest{
		Name:           name,
		DockerImageTag: dockerImageTag,
	}
	return &out
}
