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

const (
	SourceShopifyUpdateSchemasAuthMethodAPIPassword SourceShopifyUpdateSchemasAuthMethod = "api_password"
)

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

// SourceShopifyUpdateAPIPassword - API Password Auth
type SourceShopifyUpdateAPIPassword struct {
	// The API Password for your private application in the `Shopify` store.
	APIPassword string                               `json:"api_password"`
	authMethod  SourceShopifyUpdateSchemasAuthMethod `const:"api_password" json:"auth_method"`
}

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

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

func (o *SourceShopifyUpdateAPIPassword) GetAPIPassword() string {
	if o == nil {
		return ""
	}
	return o.APIPassword
}

func (o *SourceShopifyUpdateAPIPassword) GetAuthMethod() SourceShopifyUpdateSchemasAuthMethod {
	return SourceShopifyUpdateSchemasAuthMethodAPIPassword
}

type SourceShopifyUpdateAuthMethod string

const (
	SourceShopifyUpdateAuthMethodOauth20 SourceShopifyUpdateAuthMethod = "oauth2.0"
)

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

// SourceShopifyUpdateOAuth20 - OAuth2.0
type SourceShopifyUpdateOAuth20 struct {
	// The Access Token for making authenticated requests.
	AccessToken *string                       `json:"access_token,omitempty"`
	authMethod  SourceShopifyUpdateAuthMethod `const:"oauth2.0" json:"auth_method"`
	// The Client ID of the Shopify developer application.
	ClientID *string `json:"client_id,omitempty"`
	// The Client Secret of the Shopify developer application.
	ClientSecret *string `json:"client_secret,omitempty"`
}

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

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

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

func (o *SourceShopifyUpdateOAuth20) GetAuthMethod() SourceShopifyUpdateAuthMethod {
	return SourceShopifyUpdateAuthMethodOauth20
}

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

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

type SourceShopifyUpdateShopifyAuthorizationMethodType string

const (
	SourceShopifyUpdateShopifyAuthorizationMethodTypeSourceShopifyUpdateOAuth20     SourceShopifyUpdateShopifyAuthorizationMethodType = "source-shopify-update_OAuth2.0"
	SourceShopifyUpdateShopifyAuthorizationMethodTypeSourceShopifyUpdateAPIPassword SourceShopifyUpdateShopifyAuthorizationMethodType = "source-shopify-update_API Password"
)

// SourceShopifyUpdateShopifyAuthorizationMethod - The authorization method to use to retrieve data from Shopify
type SourceShopifyUpdateShopifyAuthorizationMethod struct {
	SourceShopifyUpdateOAuth20     *SourceShopifyUpdateOAuth20     `queryParam:"inline"`
	SourceShopifyUpdateAPIPassword *SourceShopifyUpdateAPIPassword `queryParam:"inline"`

	Type SourceShopifyUpdateShopifyAuthorizationMethodType
}

func CreateSourceShopifyUpdateShopifyAuthorizationMethodSourceShopifyUpdateOAuth20(sourceShopifyUpdateOAuth20 SourceShopifyUpdateOAuth20) SourceShopifyUpdateShopifyAuthorizationMethod {
	typ := SourceShopifyUpdateShopifyAuthorizationMethodTypeSourceShopifyUpdateOAuth20

	return SourceShopifyUpdateShopifyAuthorizationMethod{
		SourceShopifyUpdateOAuth20: &sourceShopifyUpdateOAuth20,
		Type:                       typ,
	}
}

func CreateSourceShopifyUpdateShopifyAuthorizationMethodSourceShopifyUpdateAPIPassword(sourceShopifyUpdateAPIPassword SourceShopifyUpdateAPIPassword) SourceShopifyUpdateShopifyAuthorizationMethod {
	typ := SourceShopifyUpdateShopifyAuthorizationMethodTypeSourceShopifyUpdateAPIPassword

	return SourceShopifyUpdateShopifyAuthorizationMethod{
		SourceShopifyUpdateAPIPassword: &sourceShopifyUpdateAPIPassword,
		Type:                           typ,
	}
}

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

	var sourceShopifyUpdateAPIPassword SourceShopifyUpdateAPIPassword = SourceShopifyUpdateAPIPassword{}
	if err := utils.UnmarshalJSON(data, &sourceShopifyUpdateAPIPassword, "", true, true); err == nil {
		u.SourceShopifyUpdateAPIPassword = &sourceShopifyUpdateAPIPassword
		u.Type = SourceShopifyUpdateShopifyAuthorizationMethodTypeSourceShopifyUpdateAPIPassword
		return nil
	}

	var sourceShopifyUpdateOAuth20 SourceShopifyUpdateOAuth20 = SourceShopifyUpdateOAuth20{}
	if err := utils.UnmarshalJSON(data, &sourceShopifyUpdateOAuth20, "", true, true); err == nil {
		u.SourceShopifyUpdateOAuth20 = &sourceShopifyUpdateOAuth20
		u.Type = SourceShopifyUpdateShopifyAuthorizationMethodTypeSourceShopifyUpdateOAuth20
		return nil
	}

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

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

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

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

type SourceShopifyUpdate struct {
	// Defines what would be a date range per single BULK Job
	BulkWindowInDays *int64 `default:"30" json:"bulk_window_in_days"`
	// The authorization method to use to retrieve data from Shopify
	Credentials *SourceShopifyUpdateShopifyAuthorizationMethod `json:"credentials,omitempty"`
	// Defines which API type (REST/BULK) to use to fetch `Transactions` data. If you are a `Shopify Plus` user, leave the default value to speed up the fetch.
	FetchTransactionsUserID *bool `default:"false" json:"fetch_transactions_user_id"`
	// The threshold, after which the single BULK Job should be checkpointed (min: 15k, max: 1M)
	JobCheckpointInterval *int64 `default:"100000" json:"job_checkpoint_interval"`
	// If enabled, the `Product Variants` stream attempts to include `Presentment prices` field (may affect the performance).
	JobProductVariantsIncludePresPrices *bool `default:"true" json:"job_product_variants_include_pres_prices"`
	// The max time in seconds, after which the single BULK Job should be `CANCELED` and retried. The bigger the value the longer the BULK Job is allowed to run.
	JobTerminationThreshold *int64 `default:"7200" json:"job_termination_threshold"`
	// The name of your Shopify store found in the URL. For example, if your URL was https://NAME.myshopify.com, then the name would be 'NAME' or 'NAME.myshopify.com'.
	Shop string `json:"shop"`
	// The date you would like to replicate data from. Format: YYYY-MM-DD. Any data before this date will not be replicated.
	StartDate *types.Date `default:"2020-01-01" json:"start_date"`
}

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

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

func (o *SourceShopifyUpdate) GetBulkWindowInDays() *int64 {
	if o == nil {
		return nil
	}
	return o.BulkWindowInDays
}

func (o *SourceShopifyUpdate) GetCredentials() *SourceShopifyUpdateShopifyAuthorizationMethod {
	if o == nil {
		return nil
	}
	return o.Credentials
}

func (o *SourceShopifyUpdate) GetFetchTransactionsUserID() *bool {
	if o == nil {
		return nil
	}
	return o.FetchTransactionsUserID
}

func (o *SourceShopifyUpdate) GetJobCheckpointInterval() *int64 {
	if o == nil {
		return nil
	}
	return o.JobCheckpointInterval
}

func (o *SourceShopifyUpdate) GetJobProductVariantsIncludePresPrices() *bool {
	if o == nil {
		return nil
	}
	return o.JobProductVariantsIncludePresPrices
}

func (o *SourceShopifyUpdate) GetJobTerminationThreshold() *int64 {
	if o == nil {
		return nil
	}
	return o.JobTerminationThreshold
}

func (o *SourceShopifyUpdate) GetShop() string {
	if o == nil {
		return ""
	}
	return o.Shop
}

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