// 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"
	"github.com/airbytehq/terraform-provider-airbyte/internal/sdk/types"
)

type SourceSquareUpdateSchemasAuthType string

const (
	SourceSquareUpdateSchemasAuthTypeAPIKey SourceSquareUpdateSchemasAuthType = "API Key"
)

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

type SourceSquareUpdateAPIKey struct {
	// The API key for a Square application
	APIKey   string                            `json:"api_key"`
	authType SourceSquareUpdateSchemasAuthType `const:"API Key" json:"auth_type"`
}

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

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

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

func (o *SourceSquareUpdateAPIKey) GetAuthType() SourceSquareUpdateSchemasAuthType {
	return SourceSquareUpdateSchemasAuthTypeAPIKey
}

type SourceSquareUpdateAuthType string

const (
	SourceSquareUpdateAuthTypeOAuth SourceSquareUpdateAuthType = "OAuth"
)

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

type SourceSquareUpdateOauthAuthentication struct {
	authType SourceSquareUpdateAuthType `const:"OAuth" json:"auth_type"`
	// The Square-issued ID of your application
	ClientID string `json:"client_id"`
	// The Square-issued application secret for your application
	ClientSecret string `json:"client_secret"`
	// A refresh token generated using the above client ID and secret
	RefreshToken string `json:"refresh_token"`
}

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

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

func (o *SourceSquareUpdateOauthAuthentication) GetAuthType() SourceSquareUpdateAuthType {
	return SourceSquareUpdateAuthTypeOAuth
}

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

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

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

type SourceSquareUpdateAuthenticationType string

const (
	SourceSquareUpdateAuthenticationTypeSourceSquareUpdateOauthAuthentication SourceSquareUpdateAuthenticationType = "source-square-update_Oauth authentication"
	SourceSquareUpdateAuthenticationTypeSourceSquareUpdateAPIKey              SourceSquareUpdateAuthenticationType = "source-square-update_API key"
)

// SourceSquareUpdateAuthentication - Choose how to authenticate to Square.
type SourceSquareUpdateAuthentication struct {
	SourceSquareUpdateOauthAuthentication *SourceSquareUpdateOauthAuthentication `queryParam:"inline"`
	SourceSquareUpdateAPIKey              *SourceSquareUpdateAPIKey              `queryParam:"inline"`

	Type SourceSquareUpdateAuthenticationType
}

func CreateSourceSquareUpdateAuthenticationSourceSquareUpdateOauthAuthentication(sourceSquareUpdateOauthAuthentication SourceSquareUpdateOauthAuthentication) SourceSquareUpdateAuthentication {
	typ := SourceSquareUpdateAuthenticationTypeSourceSquareUpdateOauthAuthentication

	return SourceSquareUpdateAuthentication{
		SourceSquareUpdateOauthAuthentication: &sourceSquareUpdateOauthAuthentication,
		Type:                                  typ,
	}
}

func CreateSourceSquareUpdateAuthenticationSourceSquareUpdateAPIKey(sourceSquareUpdateAPIKey SourceSquareUpdateAPIKey) SourceSquareUpdateAuthentication {
	typ := SourceSquareUpdateAuthenticationTypeSourceSquareUpdateAPIKey

	return SourceSquareUpdateAuthentication{
		SourceSquareUpdateAPIKey: &sourceSquareUpdateAPIKey,
		Type:                     typ,
	}
}

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

	var sourceSquareUpdateAPIKey SourceSquareUpdateAPIKey = SourceSquareUpdateAPIKey{}
	if err := utils.UnmarshalJSON(data, &sourceSquareUpdateAPIKey, "", true, true); err == nil {
		u.SourceSquareUpdateAPIKey = &sourceSquareUpdateAPIKey
		u.Type = SourceSquareUpdateAuthenticationTypeSourceSquareUpdateAPIKey
		return nil
	}

	var sourceSquareUpdateOauthAuthentication SourceSquareUpdateOauthAuthentication = SourceSquareUpdateOauthAuthentication{}
	if err := utils.UnmarshalJSON(data, &sourceSquareUpdateOauthAuthentication, "", true, true); err == nil {
		u.SourceSquareUpdateOauthAuthentication = &sourceSquareUpdateOauthAuthentication
		u.Type = SourceSquareUpdateAuthenticationTypeSourceSquareUpdateOauthAuthentication
		return nil
	}

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

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

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

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

type SourceSquareUpdate struct {
	// Choose how to authenticate to Square.
	Credentials *SourceSquareUpdateAuthentication `json:"credentials,omitempty"`
	// In some streams there is an option to include deleted objects (Items, Categories, Discounts, Taxes)
	IncludeDeletedObjects *bool `default:"false" json:"include_deleted_objects"`
	// Determines whether to use the sandbox or production environment.
	IsSandbox *bool `default:"false" json:"is_sandbox"`
	// UTC date in the format YYYY-MM-DD. Any data before this date will not be replicated. If not set, all data will be replicated.
	StartDate *types.Date `default:"2021-01-01" json:"start_date"`
}

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

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

func (o *SourceSquareUpdate) GetCredentials() *SourceSquareUpdateAuthentication {
	if o == nil {
		return nil
	}
	return o.Credentials
}

func (o *SourceSquareUpdate) GetIncludeDeletedObjects() *bool {
	if o == nil {
		return nil
	}
	return o.IncludeDeletedObjects
}

func (o *SourceSquareUpdate) GetIsSandbox() *bool {
	if o == nil {
		return nil
	}
	return o.IsSandbox
}

func (o *SourceSquareUpdate) GetStartDate() *types.Date {
	if o == nil {
		return nil
	}
	return o.StartDate
}
