package model

import "github.com/tech/sendico/pkg/mservice"

type CallbackStatus string

const (
	CallbackStatusActive   CallbackStatus = "active"
	CallbackStatusDisabled CallbackStatus = "disabled"
)

type CallbackSigningMode string

const (
	CallbackSigningModeNone       CallbackSigningMode = "none"
	CallbackSigningModeHMACSHA256 CallbackSigningMode = "hmac_sha256"
)

type CallbackBackoff struct {
	MinDelayMS int `bson:"min_ms" json:"minDelayMs"`
	MaxDelayMS int `bson:"max_ms" json:"maxDelayMs"`
}

type CallbackRetryPolicy struct {
	Backoff          CallbackBackoff     `bson:"backoff" json:"backoff"`
	SigningMode      CallbackSigningMode `bson:"signing_mode" json:"signingMode"`
	Headers          map[string]string   `bson:"headers,omitempty" json:"headers,omitempty"`
	MaxAttempts      int                 `bson:"max_attempts" json:"maxAttempts"`
	RequestTimeoutMS int                 `bson:"request_timeout_ms" json:"requestTimeoutMs"`
}

type Callback struct {
	PermissionBound `bson:",inline" json:",inline"`
	Describable     `bson:",inline" json:",inline"`
	Status          CallbackStatus      `bson:"status" json:"status"`
	URL             string              `bson:"url" json:"url"`
	EventTypes      []string            `bson:"event_types" json:"eventTypes"`
	RetryPolicy     CallbackRetryPolicy `bson:"retry_policy" json:"retryPolicy"`
}

func (*Callback) Collection() string {
	return mservice.Callbacks
}
