// 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 SourceTypeformSchemasAuthType string

const (
	SourceTypeformSchemasAuthTypeAccessToken SourceTypeformSchemasAuthType = "access_token"
)

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

type SourceTypeformPrivateToken struct {
	// Log into your Typeform account and then generate a personal Access Token.
	AccessToken string                         `json:"access_token"`
	authType    *SourceTypeformSchemasAuthType `const:"access_token" json:"auth_type,omitempty"`
}

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

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

func (o *SourceTypeformPrivateToken) GetAccessToken() string {
	if o == nil {
		return ""
	}
	return o.AccessToken
}

func (o *SourceTypeformPrivateToken) GetAuthType() *SourceTypeformSchemasAuthType {
	return SourceTypeformSchemasAuthTypeAccessToken.ToPointer()
}

type SourceTypeformAuthType string

const (
	SourceTypeformAuthTypeOauth20 SourceTypeformAuthType = "oauth2.0"
)

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

type SourceTypeformOAuth20 struct {
	// Access Token for making authenticated requests.
	AccessToken string                  `json:"access_token"`
	authType    *SourceTypeformAuthType `const:"oauth2.0" json:"auth_type,omitempty"`
	// The Client ID of the Typeform developer application.
	ClientID string `json:"client_id"`
	// The Client Secret the Typeform developer application.
	ClientSecret string `json:"client_secret"`
	// The key to refresh the expired access_token.
	RefreshToken string `json:"refresh_token"`
	// The date-time when the access token should be refreshed.
	TokenExpiryDate time.Time `json:"token_expiry_date"`
}

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

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

func (o *SourceTypeformOAuth20) GetAccessToken() string {
	if o == nil {
		return ""
	}
	return o.AccessToken
}

func (o *SourceTypeformOAuth20) GetAuthType() *SourceTypeformAuthType {
	return SourceTypeformAuthTypeOauth20.ToPointer()
}

func (o *SourceTypeformOAuth20) GetClientID() string {
	if o == nil {
		return ""
	}
	return o.ClientID
}

func (o *SourceTypeformOAuth20) GetClientSecret() string {
	if o == nil {
		return ""
	}
	return o.ClientSecret
}

func (o *SourceTypeformOAuth20) GetRefreshToken() string {
	if o == nil {
		return ""
	}
	return o.RefreshToken
}

func (o *SourceTypeformOAuth20) GetTokenExpiryDate() time.Time {
	if o == nil {
		return time.Time{}
	}
	return o.TokenExpiryDate
}

type SourceTypeformAuthorizationMethodType string

const (
	SourceTypeformAuthorizationMethodTypeSourceTypeformOAuth20      SourceTypeformAuthorizationMethodType = "source-typeform_OAuth2.0"
	SourceTypeformAuthorizationMethodTypeSourceTypeformPrivateToken SourceTypeformAuthorizationMethodType = "source-typeform_Private Token"
)

type SourceTypeformAuthorizationMethod struct {
	SourceTypeformOAuth20      *SourceTypeformOAuth20      `queryParam:"inline"`
	SourceTypeformPrivateToken *SourceTypeformPrivateToken `queryParam:"inline"`

	Type SourceTypeformAuthorizationMethodType
}

func CreateSourceTypeformAuthorizationMethodSourceTypeformOAuth20(sourceTypeformOAuth20 SourceTypeformOAuth20) SourceTypeformAuthorizationMethod {
	typ := SourceTypeformAuthorizationMethodTypeSourceTypeformOAuth20

	return SourceTypeformAuthorizationMethod{
		SourceTypeformOAuth20: &sourceTypeformOAuth20,
		Type:                  typ,
	}
}

func CreateSourceTypeformAuthorizationMethodSourceTypeformPrivateToken(sourceTypeformPrivateToken SourceTypeformPrivateToken) SourceTypeformAuthorizationMethod {
	typ := SourceTypeformAuthorizationMethodTypeSourceTypeformPrivateToken

	return SourceTypeformAuthorizationMethod{
		SourceTypeformPrivateToken: &sourceTypeformPrivateToken,
		Type:                       typ,
	}
}

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

	var sourceTypeformPrivateToken SourceTypeformPrivateToken = SourceTypeformPrivateToken{}
	if err := utils.UnmarshalJSON(data, &sourceTypeformPrivateToken, "", true, true); err == nil {
		u.SourceTypeformPrivateToken = &sourceTypeformPrivateToken
		u.Type = SourceTypeformAuthorizationMethodTypeSourceTypeformPrivateToken
		return nil
	}

	var sourceTypeformOAuth20 SourceTypeformOAuth20 = SourceTypeformOAuth20{}
	if err := utils.UnmarshalJSON(data, &sourceTypeformOAuth20, "", true, true); err == nil {
		u.SourceTypeformOAuth20 = &sourceTypeformOAuth20
		u.Type = SourceTypeformAuthorizationMethodTypeSourceTypeformOAuth20
		return nil
	}

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

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

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

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

type Typeform string

const (
	TypeformTypeform Typeform = "typeform"
)

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

type SourceTypeform struct {
	Credentials SourceTypeformAuthorizationMethod `json:"credentials"`
	// When this parameter is set, the connector will replicate data only from the input forms. Otherwise, all forms in your Typeform account will be replicated. You can find form IDs in your form URLs. For example, in the URL "https://mysite.typeform.com/to/u6nXL7" the form_id is u6nXL7. You can find form URLs on Share panel
	FormIds []string `json:"form_ids,omitempty"`
	// The date from which you'd like to replicate data for Typeform API, in the format YYYY-MM-DDT00:00:00Z. All data generated after this date will be replicated.
	StartDate  *time.Time `json:"start_date,omitempty"`
	sourceType Typeform   `const:"typeform" json:"sourceType"`
}

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

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

func (o *SourceTypeform) GetCredentials() SourceTypeformAuthorizationMethod {
	if o == nil {
		return SourceTypeformAuthorizationMethod{}
	}
	return o.Credentials
}

func (o *SourceTypeform) GetFormIds() []string {
	if o == nil {
		return nil
	}
	return o.FormIds
}

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

func (o *SourceTypeform) GetSourceType() Typeform {
	return TypeformTypeform
}
