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

package logeventcap

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

func (cfg Config) New(w *sdk.WorkflowSpecFactory, id string) OutputCap {
	ref := "trigger"
	def := sdk.StepDefinition{
		ID: id, Ref: ref,
		Inputs: sdk.StepInputs{},
		Config: map[string]any{
			"contractAddress":      cfg.ContractAddress,
			"contractEventName":    cfg.ContractEventName,
			"contractName":         cfg.ContractName,
			"contractReaderConfig": cfg.ContractReaderConfig,
		},
		CapabilityType: capabilities.CapabilityTypeTrigger,
	}

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

// HeadWrapper allows access to field from an sdk.CapDefinition[Head]
func HeadWrapper(raw sdk.CapDefinition[Head]) HeadCap {
	wrapped, ok := raw.(HeadCap)
	if ok {
		return wrapped
	}
	return &headCap{CapDefinition: raw}
}

type HeadCap interface {
	sdk.CapDefinition[Head]
	Hash() sdk.CapDefinition[string]
	Height() sdk.CapDefinition[string]
	Timestamp() sdk.CapDefinition[uint64]
	private()
}

type headCap struct {
	sdk.CapDefinition[Head]
}

func (*headCap) private() {}
func (c *headCap) Hash() sdk.CapDefinition[string] {
	return sdk.AccessField[Head, string](c.CapDefinition, "Hash")
}
func (c *headCap) Height() sdk.CapDefinition[string] {
	return sdk.AccessField[Head, string](c.CapDefinition, "Height")
}
func (c *headCap) Timestamp() sdk.CapDefinition[uint64] {
	return sdk.AccessField[Head, uint64](c.CapDefinition, "Timestamp")
}

func ConstantHead(value Head) HeadCap {
	return &headCap{CapDefinition: sdk.ConstantDefinition(value)}
}

func NewHeadFromFields(
	hash sdk.CapDefinition[string],
	height sdk.CapDefinition[string],
	timestamp sdk.CapDefinition[uint64]) HeadCap {
	return &simpleHead{
		CapDefinition: sdk.ComponentCapDefinition[Head]{
			"Hash":      hash.Ref(),
			"Height":    height.Ref(),
			"Timestamp": timestamp.Ref(),
		},
		hash:      hash,
		height:    height,
		timestamp: timestamp,
	}
}

type simpleHead struct {
	sdk.CapDefinition[Head]
	hash      sdk.CapDefinition[string]
	height    sdk.CapDefinition[string]
	timestamp sdk.CapDefinition[uint64]
}

func (c *simpleHead) Hash() sdk.CapDefinition[string] {
	return c.hash
}
func (c *simpleHead) Height() sdk.CapDefinition[string] {
	return c.height
}
func (c *simpleHead) Timestamp() sdk.CapDefinition[uint64] {
	return c.timestamp
}

func (c *simpleHead) private() {}

// OutputWrapper allows access to field from an sdk.CapDefinition[Output]
func OutputWrapper(raw sdk.CapDefinition[Output]) OutputCap {
	wrapped, ok := raw.(OutputCap)
	if ok {
		return wrapped
	}
	return &outputCap{CapDefinition: raw}
}

type OutputCap interface {
	sdk.CapDefinition[Output]
	Cursor() sdk.CapDefinition[string]
	Data() OutputDataCap
	Head() HeadCap
	private()
}

type outputCap struct {
	sdk.CapDefinition[Output]
}

func (*outputCap) private() {}
func (c *outputCap) Cursor() sdk.CapDefinition[string] {
	return sdk.AccessField[Output, string](c.CapDefinition, "Cursor")
}
func (c *outputCap) Data() OutputDataCap {
	return OutputDataWrapper(sdk.AccessField[Output, OutputData](c.CapDefinition, "Data"))
}
func (c *outputCap) Head() HeadCap {
	return HeadWrapper(sdk.AccessField[Output, Head](c.CapDefinition, "Head"))
}

func ConstantOutput(value Output) OutputCap {
	return &outputCap{CapDefinition: sdk.ConstantDefinition(value)}
}

func NewOutputFromFields(
	cursor sdk.CapDefinition[string],
	data OutputDataCap,
	head HeadCap) OutputCap {
	return &simpleOutput{
		CapDefinition: sdk.ComponentCapDefinition[Output]{
			"Cursor": cursor.Ref(),
			"Data":   data.Ref(),
			"Head":   head.Ref(),
		},
		cursor: cursor,
		data:   data,
		head:   head,
	}
}

type simpleOutput struct {
	sdk.CapDefinition[Output]
	cursor sdk.CapDefinition[string]
	data   OutputDataCap
	head   HeadCap
}

func (c *simpleOutput) Cursor() sdk.CapDefinition[string] {
	return c.cursor
}
func (c *simpleOutput) Data() OutputDataCap {
	return c.data
}
func (c *simpleOutput) Head() HeadCap {
	return c.head
}

func (c *simpleOutput) private() {}

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

type OutputDataCap sdk.CapDefinition[OutputData]
