// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.

package shared

import (
	"encoding/json"
	"errors"
	"fmt"
	"github.com/airbytehq/terraform-provider-airbyte/internal/sdk/internal/utils"
	"time"
)

type SourceJotformAPIEndpoint string

const (
	SourceJotformAPIEndpointEnterprise SourceJotformAPIEndpoint = "enterprise"
)

func (e SourceJotformAPIEndpoint) ToPointer() *SourceJotformAPIEndpoint {
	return &e
}
func (e *SourceJotformAPIEndpoint) UnmarshalJSON(data []byte) error {
	var v string
	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}
	switch v {
	case "enterprise":
		*e = SourceJotformAPIEndpoint(v)
		return nil
	default:
		return fmt.Errorf("invalid value for SourceJotformAPIEndpoint: %v", v)
	}
}

type Enterprise struct {
	apiEndpoint *SourceJotformAPIEndpoint `const:"enterprise" json:"api_endpoint,omitempty"`
	// Upgrade to Enterprise to make your API url your-domain.com/API or subdomain.jotform.com/API instead of api.jotform.com
	EnterpriseURL string `json:"enterprise_url"`
}

func (e Enterprise) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(e, "", false)
}

func (e *Enterprise) UnmarshalJSON(data []byte) error {
	if err := utils.UnmarshalJSON(data, &e, "", false, true); err != nil {
		return err
	}
	return nil
}

func (o *Enterprise) GetAPIEndpoint() *SourceJotformAPIEndpoint {
	return SourceJotformAPIEndpointEnterprise.ToPointer()
}

func (o *Enterprise) GetEnterpriseURL() string {
	if o == nil {
		return ""
	}
	return o.EnterpriseURL
}

type SourceJotformSchemasAPIEndpoint string

const (
	SourceJotformSchemasAPIEndpointBasic SourceJotformSchemasAPIEndpoint = "basic"
)

func (e SourceJotformSchemasAPIEndpoint) ToPointer() *SourceJotformSchemasAPIEndpoint {
	return &e
}
func (e *SourceJotformSchemasAPIEndpoint) UnmarshalJSON(data []byte) error {
	var v string
	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}
	switch v {
	case "basic":
		*e = SourceJotformSchemasAPIEndpoint(v)
		return nil
	default:
		return fmt.Errorf("invalid value for SourceJotformSchemasAPIEndpoint: %v", v)
	}
}

// BaseURLPrefix - You can access our API through the following URLs - Standard API Usage (Use the default API URL - https://api.jotform.com), For EU (Use the EU API URL - https://eu-api.jotform.com), For HIPAA (Use the HIPAA API URL - https://hipaa-api.jotform.com)
type BaseURLPrefix string

const (
	BaseURLPrefixStandard BaseURLPrefix = "Standard"
	BaseURLPrefixEu       BaseURLPrefix = "EU"
	BaseURLPrefixHipaa    BaseURLPrefix = "HIPAA"
)

func (e BaseURLPrefix) ToPointer() *BaseURLPrefix {
	return &e
}
func (e *BaseURLPrefix) UnmarshalJSON(data []byte) error {
	var v string
	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}
	switch v {
	case "Standard":
		fallthrough
	case "EU":
		fallthrough
	case "HIPAA":
		*e = BaseURLPrefix(v)
		return nil
	default:
		return fmt.Errorf("invalid value for BaseURLPrefix: %v", v)
	}
}

type Basic struct {
	apiEndpoint *SourceJotformSchemasAPIEndpoint `const:"basic" json:"api_endpoint,omitempty"`
	// You can access our API through the following URLs - Standard API Usage (Use the default API URL - https://api.jotform.com), For EU (Use the EU API URL - https://eu-api.jotform.com), For HIPAA (Use the HIPAA API URL - https://hipaa-api.jotform.com)
	URLPrefix *BaseURLPrefix `default:"Standard" json:"url_prefix"`
}

func (b Basic) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(b, "", false)
}

func (b *Basic) UnmarshalJSON(data []byte) error {
	if err := utils.UnmarshalJSON(data, &b, "", false, true); err != nil {
		return err
	}
	return nil
}

func (o *Basic) GetAPIEndpoint() *SourceJotformSchemasAPIEndpoint {
	return SourceJotformSchemasAPIEndpointBasic.ToPointer()
}

func (o *Basic) GetURLPrefix() *BaseURLPrefix {
	if o == nil {
		return nil
	}
	return o.URLPrefix
}

type APIEndpointType string

const (
	APIEndpointTypeBasic      APIEndpointType = "Basic"
	APIEndpointTypeEnterprise APIEndpointType = "Enterprise"
)

type APIEndpoint struct {
	Basic      *Basic      `queryParam:"inline"`
	Enterprise *Enterprise `queryParam:"inline"`

	Type APIEndpointType
}

func CreateAPIEndpointBasic(basic Basic) APIEndpoint {
	typ := APIEndpointTypeBasic

	return APIEndpoint{
		Basic: &basic,
		Type:  typ,
	}
}

func CreateAPIEndpointEnterprise(enterprise Enterprise) APIEndpoint {
	typ := APIEndpointTypeEnterprise

	return APIEndpoint{
		Enterprise: &enterprise,
		Type:       typ,
	}
}

func (u *APIEndpoint) UnmarshalJSON(data []byte) error {

	var basic Basic = Basic{}
	if err := utils.UnmarshalJSON(data, &basic, "", true, true); err == nil {
		u.Basic = &basic
		u.Type = APIEndpointTypeBasic
		return nil
	}

	var enterprise Enterprise = Enterprise{}
	if err := utils.UnmarshalJSON(data, &enterprise, "", true, true); err == nil {
		u.Enterprise = &enterprise
		u.Type = APIEndpointTypeEnterprise
		return nil
	}

	return fmt.Errorf("could not unmarshal `%s` into any supported union types for APIEndpoint", string(data))
}

func (u APIEndpoint) MarshalJSON() ([]byte, error) {
	if u.Basic != nil {
		return utils.MarshalJSON(u.Basic, "", true)
	}

	if u.Enterprise != nil {
		return utils.MarshalJSON(u.Enterprise, "", true)
	}

	return nil, errors.New("could not marshal union type APIEndpoint: all fields are null")
}

type Jotform string

const (
	JotformJotform Jotform = "jotform"
)

func (e Jotform) ToPointer() *Jotform {
	return &e
}
func (e *Jotform) UnmarshalJSON(data []byte) error {
	var v string
	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}
	switch v {
	case "jotform":
		*e = Jotform(v)
		return nil
	default:
		return fmt.Errorf("invalid value for Jotform: %v", v)
	}
}

type SourceJotform struct {
	APIEndpoint APIEndpoint `json:"api_endpoint"`
	APIKey      string      `json:"api_key"`
	EndDate     time.Time   `json:"end_date"`
	StartDate   time.Time   `json:"start_date"`
	sourceType  Jotform     `const:"jotform" json:"sourceType"`
}

func (s SourceJotform) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(s, "", false)
}

func (s *SourceJotform) UnmarshalJSON(data []byte) error {
	if err := utils.UnmarshalJSON(data, &s, "", false, false); err != nil {
		return err
	}
	return nil
}

func (o *SourceJotform) GetAPIEndpoint() APIEndpoint {
	if o == nil {
		return APIEndpoint{}
	}
	return o.APIEndpoint
}

func (o *SourceJotform) GetAPIKey() string {
	if o == nil {
		return ""
	}
	return o.APIKey
}

func (o *SourceJotform) GetEndDate() time.Time {
	if o == nil {
		return time.Time{}
	}
	return o.EndDate
}

func (o *SourceJotform) GetStartDate() time.Time {
	if o == nil {
		return time.Time{}
	}
	return o.StartDate
}

func (o *SourceJotform) GetSourceType() Jotform {
	return JotformJotform
}
