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

const (
	SourceShopifySchemasAuthMethodAPIPassword SourceShopifySchemasAuthMethod = "api_password"
)

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

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

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

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

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

func (o *APIPassword) GetAuthMethod() SourceShopifySchemasAuthMethod {
	return SourceShopifySchemasAuthMethodAPIPassword
}

type SourceShopifyAuthMethod string

const (
	SourceShopifyAuthMethodOauth20 SourceShopifyAuthMethod = "oauth2.0"
)

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

// SourceShopifyOAuth20 - OAuth2.0
type SourceShopifyOAuth20 struct {
	// The Access Token for making authenticated requests.
	AccessToken *string                 `json:"access_token,omitempty"`
	authMethod  SourceShopifyAuthMethod `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 SourceShopifyOAuth20) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(s, "", false)
}

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

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

func (o *SourceShopifyOAuth20) GetAuthMethod() SourceShopifyAuthMethod {
	return SourceShopifyAuthMethodOauth20
}

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

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

type ShopifyAuthorizationMethodType string

const (
	ShopifyAuthorizationMethodTypeSourceShopifyOAuth20 ShopifyAuthorizationMethodType = "source-shopify_OAuth2.0"
	ShopifyAuthorizationMethodTypeAPIPassword          ShopifyAuthorizationMethodType = "API Password"
)

// ShopifyAuthorizationMethod - The authorization method to use to retrieve data from Shopify
type ShopifyAuthorizationMethod struct {
	SourceShopifyOAuth20 *SourceShopifyOAuth20 `queryParam:"inline"`
	APIPassword          *APIPassword          `queryParam:"inline"`

	Type ShopifyAuthorizationMethodType
}

func CreateShopifyAuthorizationMethodSourceShopifyOAuth20(sourceShopifyOAuth20 SourceShopifyOAuth20) ShopifyAuthorizationMethod {
	typ := ShopifyAuthorizationMethodTypeSourceShopifyOAuth20

	return ShopifyAuthorizationMethod{
		SourceShopifyOAuth20: &sourceShopifyOAuth20,
		Type:                 typ,
	}
}

func CreateShopifyAuthorizationMethodAPIPassword(apiPassword APIPassword) ShopifyAuthorizationMethod {
	typ := ShopifyAuthorizationMethodTypeAPIPassword

	return ShopifyAuthorizationMethod{
		APIPassword: &apiPassword,
		Type:        typ,
	}
}

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

	var apiPassword APIPassword = APIPassword{}
	if err := utils.UnmarshalJSON(data, &apiPassword, "", true, true); err == nil {
		u.APIPassword = &apiPassword
		u.Type = ShopifyAuthorizationMethodTypeAPIPassword
		return nil
	}

	var sourceShopifyOAuth20 SourceShopifyOAuth20 = SourceShopifyOAuth20{}
	if err := utils.UnmarshalJSON(data, &sourceShopifyOAuth20, "", true, true); err == nil {
		u.SourceShopifyOAuth20 = &sourceShopifyOAuth20
		u.Type = ShopifyAuthorizationMethodTypeSourceShopifyOAuth20
		return nil
	}

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

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

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

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

type Shopify string

const (
	ShopifyShopify Shopify = "shopify"
)

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

type SourceShopify 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 *ShopifyAuthorizationMethod `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"`
	sourceType Shopify     `const:"shopify" json:"sourceType"`
}

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

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

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

func (o *SourceShopify) GetCredentials() *ShopifyAuthorizationMethod {
	if o == nil {
		return nil
	}
	return o.Credentials
}

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

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

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

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

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

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

func (o *SourceShopify) GetSourceType() Shopify {
	return ShopifyShopify
}
