// Package svix this file is @generated DO NOT EDIT
package models

import (
	"encoding/json"
	"fmt"
)

// When creating an IngestSourceIn, use the appropriate config structure based on the Type:
//   - "generic-webhook": No config needed (nil or just ignore the config field)
//   - "adobe-sign": Use AdobeSignConfig
//   - "airwallex": Use AirwallexConfig
//   - "checkbook": Use CheckbookConfig
//   - "cron": Use CronConfig
//   - "docusign": Use DocusignConfig
//   - "easypost": Use EasypostConfig
//   - "github": Use GithubConfig
//   - "hubspot": Use HubspotConfig
//   - "meta": Use MetaConfig
//   - "nango": Use NangoConfig
//   - "openclaw": Use OpenClawConfig
//   - "orum-io": Use OrumIoConfig
//   - "panda-doc": Use PandaDocConfig
//   - "port-io": Use PortIoConfig
//   - "rutter": Use RutterConfig
//   - "segment": Use SegmentConfig
//   - "shopify": Use ShopifyConfig
//   - "slack": Use SlackConfig
//   - "stripe": Use StripeConfig
//   - "beehiiv","brex","clerk","guesty","incident-io","lithic","nash","pleo","psi-fi","replicate","resend","safebase","sardine","stych","svix","open-ai","render": Use SvixConfig
//   - "tailscale": Use TailscaleConfig
//   - "telnyx": Use TelnyxConfig
//   - "vapi": Use VapiConfig
//   - "veriff": Use VeriffConfig
//   - "vgs": Use VgsConfig
//   - "zoom": Use ZoomConfig
type IngestSourceIn struct {
	Name     string               `json:"name"`
	Uid      *string              `json:"uid,omitempty"` // The Source's UID.
	Metadata *map[string]string   `json:"metadata,omitempty"`
	Type     IngestSourceInType   `json:"type"`
	Config   IngestSourceInConfig `json:"config"`
}

type IngestSourceInType string

const (
	IngestSourceInTypeGenericWebhook IngestSourceInType = "generic-webhook"
	IngestSourceInTypeCron           IngestSourceInType = "cron"
	IngestSourceInTypeAdobeSign      IngestSourceInType = "adobe-sign"
	IngestSourceInTypeBeehiiv        IngestSourceInType = "beehiiv"
	IngestSourceInTypeBrex           IngestSourceInType = "brex"
	IngestSourceInTypeCheckbook      IngestSourceInType = "checkbook"
	IngestSourceInTypeClerk          IngestSourceInType = "clerk"
	IngestSourceInTypeDocusign       IngestSourceInType = "docusign"
	IngestSourceInTypeEasypost       IngestSourceInType = "easypost"
	IngestSourceInTypeGithub         IngestSourceInType = "github"
	IngestSourceInTypeGuesty         IngestSourceInType = "guesty"
	IngestSourceInTypeHubspot        IngestSourceInType = "hubspot"
	IngestSourceInTypeIncidentIo     IngestSourceInType = "incident-io"
	IngestSourceInTypeLithic         IngestSourceInType = "lithic"
	IngestSourceInTypeMeta           IngestSourceInType = "meta"
	IngestSourceInTypeNango          IngestSourceInType = "nango"
	IngestSourceInTypeNash           IngestSourceInType = "nash"
	IngestSourceInTypeOpenclaw       IngestSourceInType = "openclaw"
	IngestSourceInTypeOrumIo         IngestSourceInType = "orum-io"
	IngestSourceInTypePandaDoc       IngestSourceInType = "panda-doc"
	IngestSourceInTypePortIo         IngestSourceInType = "port-io"
	IngestSourceInTypePleo           IngestSourceInType = "pleo"
	IngestSourceInTypePsiFi          IngestSourceInType = "psi-fi"
	IngestSourceInTypeReplicate      IngestSourceInType = "replicate"
	IngestSourceInTypeResend         IngestSourceInType = "resend"
	IngestSourceInTypeRutter         IngestSourceInType = "rutter"
	IngestSourceInTypeSafebase       IngestSourceInType = "safebase"
	IngestSourceInTypeSardine        IngestSourceInType = "sardine"
	IngestSourceInTypeSegment        IngestSourceInType = "segment"
	IngestSourceInTypeShopify        IngestSourceInType = "shopify"
	IngestSourceInTypeSlack          IngestSourceInType = "slack"
	IngestSourceInTypeStripe         IngestSourceInType = "stripe"
	IngestSourceInTypeStych          IngestSourceInType = "stych"
	IngestSourceInTypeSvix           IngestSourceInType = "svix"
	IngestSourceInTypeZoom           IngestSourceInType = "zoom"
	IngestSourceInTypeTailscale      IngestSourceInType = "tailscale"
	IngestSourceInTypeTelnyx         IngestSourceInType = "telnyx"
	IngestSourceInTypeVapi           IngestSourceInType = "vapi"
	IngestSourceInTypeOpenAi         IngestSourceInType = "open-ai"
	IngestSourceInTypeRender         IngestSourceInType = "render"
	IngestSourceInTypeVeriff         IngestSourceInType = "veriff"
	IngestSourceInTypeAirwallex      IngestSourceInType = "airwallex"
	IngestSourceInTypeVgs            IngestSourceInType = "vgs"
)

type IngestSourceInConfig interface {
	isIngestSourceInConfig()
}

func (emptyMap) isIngestSourceInConfig()        {}
func (CronConfig) isIngestSourceInConfig()      {}
func (AdobeSignConfig) isIngestSourceInConfig() {}
func (SvixConfig) isIngestSourceInConfig()      {}
func (CheckbookConfig) isIngestSourceInConfig() {}
func (DocusignConfig) isIngestSourceInConfig()  {}
func (EasypostConfig) isIngestSourceInConfig()  {}
func (GithubConfig) isIngestSourceInConfig()    {}
func (HubspotConfig) isIngestSourceInConfig()   {}
func (MetaConfig) isIngestSourceInConfig()      {}
func (NangoConfig) isIngestSourceInConfig()     {}
func (OpenClawConfig) isIngestSourceInConfig()  {}
func (OrumIoConfig) isIngestSourceInConfig()    {}
func (PandaDocConfig) isIngestSourceInConfig()  {}
func (PortIoConfig) isIngestSourceInConfig()    {}
func (RutterConfig) isIngestSourceInConfig()    {}
func (SegmentConfig) isIngestSourceInConfig()   {}
func (ShopifyConfig) isIngestSourceInConfig()   {}
func (SlackConfig) isIngestSourceInConfig()     {}
func (StripeConfig) isIngestSourceInConfig()    {}
func (ZoomConfig) isIngestSourceInConfig()      {}
func (TailscaleConfig) isIngestSourceInConfig() {}
func (TelnyxConfig) isIngestSourceInConfig()    {}
func (VapiConfig) isIngestSourceInConfig()      {}
func (VeriffConfig) isIngestSourceInConfig()    {}
func (AirwallexConfig) isIngestSourceInConfig() {}
func (VgsConfig) isIngestSourceInConfig()       {}

func (i *IngestSourceIn) UnmarshalJSON(data []byte) error {
	type Alias IngestSourceIn
	aux := struct {
		*Alias
		Config json.RawMessage `json:"config"`
	}{Alias: (*Alias)(i)}

	if err := json.Unmarshal(data, &aux); err != nil {
		return err
	}

	var err error
	switch i.Type {
	case "generic-webhook":
	case "adobe-sign":
		var c AdobeSignConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "airwallex":
		var c AirwallexConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "checkbook":
		var c CheckbookConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "cron":
		var c CronConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "docusign":
		var c DocusignConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "easypost":
		var c EasypostConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "github":
		var c GithubConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "hubspot":
		var c HubspotConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "meta":
		var c MetaConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "nango":
		var c NangoConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "openclaw":
		var c OpenClawConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "orum-io":
		var c OrumIoConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "panda-doc":
		var c PandaDocConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "port-io":
		var c PortIoConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "rutter":
		var c RutterConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "segment":
		var c SegmentConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "shopify":
		var c ShopifyConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "slack":
		var c SlackConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "stripe":
		var c StripeConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "beehiiv", "brex", "clerk", "guesty", "incident-io", "lithic", "nash", "pleo", "psi-fi", "replicate", "resend", "safebase", "sardine", "stych", "svix", "open-ai", "render":
		var c SvixConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "tailscale":
		var c TailscaleConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "telnyx":
		var c TelnyxConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "vapi":
		var c VapiConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "veriff":
		var c VeriffConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "vgs":
		var c VgsConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	case "zoom":
		var c ZoomConfig
		err = json.Unmarshal(aux.Config, &c)
		i.Config = c
	default:
		// should be unreachable
		return fmt.Errorf("unexpected type %s", i.Type)
	}
	return err
}

var IngestSourceInTypeWithNoConfig = map[string]bool{
	"generic-webhook": true,
}

func (i IngestSourceIn) MarshalJSON() ([]byte, error) {
	type Alias IngestSourceIn
	if _, found := IngestSourceInTypeWithNoConfig[string(i.Type)]; found {
		i.Config = emptyMap{}
	}
	return json.Marshal(&struct{ Alias }{Alias: (Alias)(i)})
}

var IngestSourceInTypeFromString = map[string]IngestSourceInType{
	"generic-webhook": IngestSourceInTypeGenericWebhook,
	"cron":            IngestSourceInTypeCron,
	"adobe-sign":      IngestSourceInTypeAdobeSign,
	"beehiiv":         IngestSourceInTypeBeehiiv,
	"brex":            IngestSourceInTypeBrex,
	"checkbook":       IngestSourceInTypeCheckbook,
	"clerk":           IngestSourceInTypeClerk,
	"docusign":        IngestSourceInTypeDocusign,
	"easypost":        IngestSourceInTypeEasypost,
	"github":          IngestSourceInTypeGithub,
	"guesty":          IngestSourceInTypeGuesty,
	"hubspot":         IngestSourceInTypeHubspot,
	"incident-io":     IngestSourceInTypeIncidentIo,
	"lithic":          IngestSourceInTypeLithic,
	"meta":            IngestSourceInTypeMeta,
	"nango":           IngestSourceInTypeNango,
	"nash":            IngestSourceInTypeNash,
	"openclaw":        IngestSourceInTypeOpenclaw,
	"orum-io":         IngestSourceInTypeOrumIo,
	"panda-doc":       IngestSourceInTypePandaDoc,
	"port-io":         IngestSourceInTypePortIo,
	"pleo":            IngestSourceInTypePleo,
	"psi-fi":          IngestSourceInTypePsiFi,
	"replicate":       IngestSourceInTypeReplicate,
	"resend":          IngestSourceInTypeResend,
	"rutter":          IngestSourceInTypeRutter,
	"safebase":        IngestSourceInTypeSafebase,
	"sardine":         IngestSourceInTypeSardine,
	"segment":         IngestSourceInTypeSegment,
	"shopify":         IngestSourceInTypeShopify,
	"slack":           IngestSourceInTypeSlack,
	"stripe":          IngestSourceInTypeStripe,
	"stych":           IngestSourceInTypeStych,
	"svix":            IngestSourceInTypeSvix,
	"zoom":            IngestSourceInTypeZoom,
	"tailscale":       IngestSourceInTypeTailscale,
	"telnyx":          IngestSourceInTypeTelnyx,
	"vapi":            IngestSourceInTypeVapi,
	"open-ai":         IngestSourceInTypeOpenAi,
	"render":          IngestSourceInTypeRender,
	"veriff":          IngestSourceInTypeVeriff,
	"airwallex":       IngestSourceInTypeAirwallex,
	"vgs":             IngestSourceInTypeVgs,
}
