// Code generated by github.com/smartcontractkit/chainlink-common/pkg/capabilities/cli, DO NOT EDIT.

package webapicap

import (
	"github.com/smartcontractkit/chainlink-common/pkg/capabilities"
	"github.com/smartcontractkit/chainlink-common/pkg/workflows/sdk"
)

func (cfg TargetConfig) New(w *sdk.WorkflowSpecFactory, input TargetInput) {

	def := sdk.StepDefinition{
		ID:     "web-api-target@1.0.0",
		Inputs: input.ToSteps(),
		Config: map[string]any{
			"deliveryMode": cfg.DeliveryMode,
			"retryCount":   cfg.RetryCount,
			"timeoutMs":    cfg.TimeoutMs,
		},
		CapabilityType: capabilities.CapabilityTypeTarget,
	}

	step := sdk.Step[struct{}]{Definition: def}
	step.AddTo(w)
}

type TargetInput struct {
	Body    sdk.CapDefinition[string]
	Headers sdk.CapDefinition[TargetPayloadHeaders]
	Method  sdk.CapDefinition[string]
	Url     sdk.CapDefinition[string]
}

func (input TargetInput) ToSteps() sdk.StepInputs {
	return sdk.StepInputs{
		Mapping: map[string]any{
			"body":    input.Body.Ref(),
			"headers": input.Headers.Ref(),
			"method":  input.Method.Ref(),
			"url":     input.Url.Ref(),
		},
	}
}
