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

package webapicap

import (
	"encoding/json"
	"fmt"
)

type RateLimiterConfig struct {
	// GlobalBurst corresponds to the JSON schema field "globalBurst".
	GlobalBurst int64 `json:"globalBurst" yaml:"globalBurst" mapstructure:"globalBurst"`

	// GlobalRPS corresponds to the JSON schema field "globalRPS".
	GlobalRPS float64 `json:"globalRPS" yaml:"globalRPS" mapstructure:"globalRPS"`

	// PerSenderBurst corresponds to the JSON schema field "perSenderBurst".
	PerSenderBurst int64 `json:"perSenderBurst" yaml:"perSenderBurst" mapstructure:"perSenderBurst"`

	// PerSenderRPS corresponds to the JSON schema field "perSenderRPS".
	PerSenderRPS float64 `json:"perSenderRPS" yaml:"perSenderRPS" mapstructure:"perSenderRPS"`
}

// UnmarshalJSON implements json.Unmarshaler.
func (j *RateLimiterConfig) UnmarshalJSON(b []byte) error {
	var raw map[string]interface{}
	if err := json.Unmarshal(b, &raw); err != nil {
		return err
	}
	if _, ok := raw["globalBurst"]; raw != nil && !ok {
		return fmt.Errorf("field globalBurst in RateLimiterConfig: required")
	}
	if _, ok := raw["globalRPS"]; raw != nil && !ok {
		return fmt.Errorf("field globalRPS in RateLimiterConfig: required")
	}
	if _, ok := raw["perSenderBurst"]; raw != nil && !ok {
		return fmt.Errorf("field perSenderBurst in RateLimiterConfig: required")
	}
	if _, ok := raw["perSenderRPS"]; raw != nil && !ok {
		return fmt.Errorf("field perSenderRPS in RateLimiterConfig: required")
	}
	type Plain RateLimiterConfig
	var plain Plain
	if err := json.Unmarshal(b, &plain); err != nil {
		return err
	}
	*j = RateLimiterConfig(plain)
	return nil
}

type Trigger struct {
	// Config corresponds to the JSON schema field "Config".
	Config *TriggerConfig `json:"Config,omitempty" yaml:"Config,omitempty" mapstructure:"Config,omitempty"`

	// Outputs corresponds to the JSON schema field "Outputs".
	Outputs *TriggerRequestPayload `json:"Outputs,omitempty" yaml:"Outputs,omitempty" mapstructure:"Outputs,omitempty"`
}

// See https://gateway-us-1.chain.link/web-api-trigger
type TriggerConfig struct {
	// AllowedSenders corresponds to the JSON schema field "allowedSenders".
	AllowedSenders []string `json:"allowedSenders" yaml:"allowedSenders" mapstructure:"allowedSenders"`

	// AllowedTopics corresponds to the JSON schema field "allowedTopics".
	AllowedTopics []string `json:"allowedTopics" yaml:"allowedTopics" mapstructure:"allowedTopics"`

	// RateLimiter corresponds to the JSON schema field "rateLimiter".
	RateLimiter RateLimiterConfig `json:"rateLimiter" yaml:"rateLimiter" mapstructure:"rateLimiter"`

	// RequiredParams corresponds to the JSON schema field "requiredParams".
	RequiredParams []string `json:"requiredParams" yaml:"requiredParams" mapstructure:"requiredParams"`
}

// UnmarshalJSON implements json.Unmarshaler.
func (j *TriggerConfig) UnmarshalJSON(b []byte) error {
	var raw map[string]interface{}
	if err := json.Unmarshal(b, &raw); err != nil {
		return err
	}
	if _, ok := raw["allowedSenders"]; raw != nil && !ok {
		return fmt.Errorf("field allowedSenders in TriggerConfig: required")
	}
	if _, ok := raw["allowedTopics"]; raw != nil && !ok {
		return fmt.Errorf("field allowedTopics in TriggerConfig: required")
	}
	if _, ok := raw["rateLimiter"]; raw != nil && !ok {
		return fmt.Errorf("field rateLimiter in TriggerConfig: required")
	}
	if _, ok := raw["requiredParams"]; raw != nil && !ok {
		return fmt.Errorf("field requiredParams in TriggerConfig: required")
	}
	type Plain TriggerConfig
	var plain Plain
	if err := json.Unmarshal(b, &plain); err != nil {
		return err
	}
	*j = TriggerConfig(plain)
	return nil
}

type TriggerRequestPayload struct {
	// Key-value pairs for the workflow engine, untranslated.
	Params TriggerRequestPayloadParams `json:"params" yaml:"params" mapstructure:"params"`

	// Timestamp of the event (unix time), needs to be within certain freshness to be
	// processed.
	Timestamp int64 `json:"timestamp" yaml:"timestamp" mapstructure:"timestamp"`

	// Topics corresponds to the JSON schema field "topics".
	Topics []string `json:"topics" yaml:"topics" mapstructure:"topics"`

	// Uniquely identifies generated event (scoped to trigger_id and sender).
	TriggerEventId string `json:"trigger_event_id" yaml:"trigger_event_id" mapstructure:"trigger_event_id"`

	// ID of the trigger corresponding to the capability ID.
	TriggerId string `json:"trigger_id" yaml:"trigger_id" mapstructure:"trigger_id"`
}

// Key-value pairs for the workflow engine, untranslated.
type TriggerRequestPayloadParams map[string]interface{}

// UnmarshalJSON implements json.Unmarshaler.
func (j *TriggerRequestPayload) UnmarshalJSON(b []byte) error {
	var raw map[string]interface{}
	if err := json.Unmarshal(b, &raw); err != nil {
		return err
	}
	if _, ok := raw["params"]; raw != nil && !ok {
		return fmt.Errorf("field params in TriggerRequestPayload: required")
	}
	if _, ok := raw["timestamp"]; raw != nil && !ok {
		return fmt.Errorf("field timestamp in TriggerRequestPayload: required")
	}
	if _, ok := raw["topics"]; raw != nil && !ok {
		return fmt.Errorf("field topics in TriggerRequestPayload: required")
	}
	if _, ok := raw["trigger_event_id"]; raw != nil && !ok {
		return fmt.Errorf("field trigger_event_id in TriggerRequestPayload: required")
	}
	if _, ok := raw["trigger_id"]; raw != nil && !ok {
		return fmt.Errorf("field trigger_id in TriggerRequestPayload: required")
	}
	type Plain TriggerRequestPayload
	var plain Plain
	if err := json.Unmarshal(b, &plain); err != nil {
		return err
	}
	*j = TriggerRequestPayload(plain)
	return nil
}
