// 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 TriggerConfig) New(w *sdk.WorkflowSpecFactory) TriggerRequestPayloadCap {
	ref := "trigger"
	def := sdk.StepDefinition{
		ID: "web-api-trigger@1.0.0", Ref: ref,
		Inputs: sdk.StepInputs{},
		Config: map[string]any{
			"allowedSenders": cfg.AllowedSenders,
			"allowedTopics":  cfg.AllowedTopics,
			"rateLimiter":    cfg.RateLimiter,
			"requiredParams": cfg.RequiredParams,
		},
		CapabilityType: capabilities.CapabilityTypeTrigger,
	}

	step := sdk.Step[TriggerRequestPayload]{Definition: def}
	raw := step.AddTo(w)
	return TriggerRequestPayloadWrapper(raw)
}

// RateLimiterConfigWrapper allows access to field from an sdk.CapDefinition[RateLimiterConfig]
func RateLimiterConfigWrapper(raw sdk.CapDefinition[RateLimiterConfig]) RateLimiterConfigCap {
	wrapped, ok := raw.(RateLimiterConfigCap)
	if ok {
		return wrapped
	}
	return &rateLimiterConfigCap{CapDefinition: raw}
}

type RateLimiterConfigCap interface {
	sdk.CapDefinition[RateLimiterConfig]
	GlobalBurst() sdk.CapDefinition[int64]
	GlobalRPS() sdk.CapDefinition[float64]
	PerSenderBurst() sdk.CapDefinition[int64]
	PerSenderRPS() sdk.CapDefinition[float64]
	private()
}

type rateLimiterConfigCap struct {
	sdk.CapDefinition[RateLimiterConfig]
}

func (*rateLimiterConfigCap) private() {}
func (c *rateLimiterConfigCap) GlobalBurst() sdk.CapDefinition[int64] {
	return sdk.AccessField[RateLimiterConfig, int64](c.CapDefinition, "globalBurst")
}
func (c *rateLimiterConfigCap) GlobalRPS() sdk.CapDefinition[float64] {
	return sdk.AccessField[RateLimiterConfig, float64](c.CapDefinition, "globalRPS")
}
func (c *rateLimiterConfigCap) PerSenderBurst() sdk.CapDefinition[int64] {
	return sdk.AccessField[RateLimiterConfig, int64](c.CapDefinition, "perSenderBurst")
}
func (c *rateLimiterConfigCap) PerSenderRPS() sdk.CapDefinition[float64] {
	return sdk.AccessField[RateLimiterConfig, float64](c.CapDefinition, "perSenderRPS")
}

func ConstantRateLimiterConfig(value RateLimiterConfig) RateLimiterConfigCap {
	return &rateLimiterConfigCap{CapDefinition: sdk.ConstantDefinition(value)}
}

func NewRateLimiterConfigFromFields(
	globalBurst sdk.CapDefinition[int64],
	globalRPS sdk.CapDefinition[float64],
	perSenderBurst sdk.CapDefinition[int64],
	perSenderRPS sdk.CapDefinition[float64]) RateLimiterConfigCap {
	return &simpleRateLimiterConfig{
		CapDefinition: sdk.ComponentCapDefinition[RateLimiterConfig]{
			"globalBurst":    globalBurst.Ref(),
			"globalRPS":      globalRPS.Ref(),
			"perSenderBurst": perSenderBurst.Ref(),
			"perSenderRPS":   perSenderRPS.Ref(),
		},
		globalBurst:    globalBurst,
		globalRPS:      globalRPS,
		perSenderBurst: perSenderBurst,
		perSenderRPS:   perSenderRPS,
	}
}

type simpleRateLimiterConfig struct {
	sdk.CapDefinition[RateLimiterConfig]
	globalBurst    sdk.CapDefinition[int64]
	globalRPS      sdk.CapDefinition[float64]
	perSenderBurst sdk.CapDefinition[int64]
	perSenderRPS   sdk.CapDefinition[float64]
}

func (c *simpleRateLimiterConfig) GlobalBurst() sdk.CapDefinition[int64] {
	return c.globalBurst
}
func (c *simpleRateLimiterConfig) GlobalRPS() sdk.CapDefinition[float64] {
	return c.globalRPS
}
func (c *simpleRateLimiterConfig) PerSenderBurst() sdk.CapDefinition[int64] {
	return c.perSenderBurst
}
func (c *simpleRateLimiterConfig) PerSenderRPS() sdk.CapDefinition[float64] {
	return c.perSenderRPS
}

func (c *simpleRateLimiterConfig) private() {}

// TriggerRequestPayloadWrapper allows access to field from an sdk.CapDefinition[TriggerRequestPayload]
func TriggerRequestPayloadWrapper(raw sdk.CapDefinition[TriggerRequestPayload]) TriggerRequestPayloadCap {
	wrapped, ok := raw.(TriggerRequestPayloadCap)
	if ok {
		return wrapped
	}
	return &triggerRequestPayloadCap{CapDefinition: raw}
}

type TriggerRequestPayloadCap interface {
	sdk.CapDefinition[TriggerRequestPayload]
	Params() TriggerRequestPayloadParamsCap
	Timestamp() sdk.CapDefinition[int64]
	Topics() sdk.CapDefinition[[]string]
	TriggerEventId() sdk.CapDefinition[string]
	TriggerId() sdk.CapDefinition[string]
	private()
}

type triggerRequestPayloadCap struct {
	sdk.CapDefinition[TriggerRequestPayload]
}

func (*triggerRequestPayloadCap) private() {}
func (c *triggerRequestPayloadCap) Params() TriggerRequestPayloadParamsCap {
	return TriggerRequestPayloadParamsWrapper(sdk.AccessField[TriggerRequestPayload, TriggerRequestPayloadParams](c.CapDefinition, "params"))
}
func (c *triggerRequestPayloadCap) Timestamp() sdk.CapDefinition[int64] {
	return sdk.AccessField[TriggerRequestPayload, int64](c.CapDefinition, "timestamp")
}
func (c *triggerRequestPayloadCap) Topics() sdk.CapDefinition[[]string] {
	return sdk.AccessField[TriggerRequestPayload, []string](c.CapDefinition, "topics")
}
func (c *triggerRequestPayloadCap) TriggerEventId() sdk.CapDefinition[string] {
	return sdk.AccessField[TriggerRequestPayload, string](c.CapDefinition, "trigger_event_id")
}
func (c *triggerRequestPayloadCap) TriggerId() sdk.CapDefinition[string] {
	return sdk.AccessField[TriggerRequestPayload, string](c.CapDefinition, "trigger_id")
}

func ConstantTriggerRequestPayload(value TriggerRequestPayload) TriggerRequestPayloadCap {
	return &triggerRequestPayloadCap{CapDefinition: sdk.ConstantDefinition(value)}
}

func NewTriggerRequestPayloadFromFields(
	params TriggerRequestPayloadParamsCap,
	timestamp sdk.CapDefinition[int64],
	topics sdk.CapDefinition[[]string],
	triggerEventId sdk.CapDefinition[string],
	triggerId sdk.CapDefinition[string]) TriggerRequestPayloadCap {
	return &simpleTriggerRequestPayload{
		CapDefinition: sdk.ComponentCapDefinition[TriggerRequestPayload]{
			"params":           params.Ref(),
			"timestamp":        timestamp.Ref(),
			"topics":           topics.Ref(),
			"trigger_event_id": triggerEventId.Ref(),
			"trigger_id":       triggerId.Ref(),
		},
		params:         params,
		timestamp:      timestamp,
		topics:         topics,
		triggerEventId: triggerEventId,
		triggerId:      triggerId,
	}
}

type simpleTriggerRequestPayload struct {
	sdk.CapDefinition[TriggerRequestPayload]
	params         TriggerRequestPayloadParamsCap
	timestamp      sdk.CapDefinition[int64]
	topics         sdk.CapDefinition[[]string]
	triggerEventId sdk.CapDefinition[string]
	triggerId      sdk.CapDefinition[string]
}

func (c *simpleTriggerRequestPayload) Params() TriggerRequestPayloadParamsCap {
	return c.params
}
func (c *simpleTriggerRequestPayload) Timestamp() sdk.CapDefinition[int64] {
	return c.timestamp
}
func (c *simpleTriggerRequestPayload) Topics() sdk.CapDefinition[[]string] {
	return c.topics
}
func (c *simpleTriggerRequestPayload) TriggerEventId() sdk.CapDefinition[string] {
	return c.triggerEventId
}
func (c *simpleTriggerRequestPayload) TriggerId() sdk.CapDefinition[string] {
	return c.triggerId
}

func (c *simpleTriggerRequestPayload) private() {}

// TriggerRequestPayloadParamsWrapper allows access to field from an sdk.CapDefinition[TriggerRequestPayloadParams]
func TriggerRequestPayloadParamsWrapper(raw sdk.CapDefinition[TriggerRequestPayloadParams]) TriggerRequestPayloadParamsCap {
	wrapped, ok := raw.(TriggerRequestPayloadParamsCap)
	if ok {
		return wrapped
	}
	return TriggerRequestPayloadParamsCap(raw)
}

type TriggerRequestPayloadParamsCap sdk.CapDefinition[TriggerRequestPayloadParams]
