// 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"
)

type SourceGoogleSheetsSchemasAuthType string

const (
	SourceGoogleSheetsSchemasAuthTypeService SourceGoogleSheetsSchemasAuthType = "Service"
)

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

type SourceGoogleSheetsServiceAccountKeyAuthentication struct {
	authType SourceGoogleSheetsSchemasAuthType `const:"Service" json:"auth_type"`
	// The JSON key of the service account to use for authorization. Read more <a href="https://cloud.google.com/iam/docs/creating-managing-service-account-keys#creating_service_account_keys">here</a>.
	ServiceAccountInfo string `json:"service_account_info"`
}

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

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

func (o *SourceGoogleSheetsServiceAccountKeyAuthentication) GetAuthType() SourceGoogleSheetsSchemasAuthType {
	return SourceGoogleSheetsSchemasAuthTypeService
}

func (o *SourceGoogleSheetsServiceAccountKeyAuthentication) GetServiceAccountInfo() string {
	if o == nil {
		return ""
	}
	return o.ServiceAccountInfo
}

type SourceGoogleSheetsAuthType string

const (
	SourceGoogleSheetsAuthTypeClient SourceGoogleSheetsAuthType = "Client"
)

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

type SourceGoogleSheetsAuthenticateViaGoogleOAuth struct {
	authType SourceGoogleSheetsAuthType `const:"Client" json:"auth_type"`
	// Enter your Google application's Client ID. See <a href='https://developers.google.com/identity/protocols/oauth2'>Google's documentation</a> for more information.
	ClientID string `json:"client_id"`
	// Enter your Google application's Client Secret. See <a href='https://developers.google.com/identity/protocols/oauth2'>Google's documentation</a> for more information.
	ClientSecret string `json:"client_secret"`
	// Enter your Google application's refresh token. See <a href='https://developers.google.com/identity/protocols/oauth2'>Google's documentation</a> for more information.
	RefreshToken string `json:"refresh_token"`
}

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

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

func (o *SourceGoogleSheetsAuthenticateViaGoogleOAuth) GetAuthType() SourceGoogleSheetsAuthType {
	return SourceGoogleSheetsAuthTypeClient
}

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

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

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

type SourceGoogleSheetsAuthenticationType string

const (
	SourceGoogleSheetsAuthenticationTypeSourceGoogleSheetsAuthenticateViaGoogleOAuth      SourceGoogleSheetsAuthenticationType = "source-google-sheets_Authenticate via Google (OAuth)"
	SourceGoogleSheetsAuthenticationTypeSourceGoogleSheetsServiceAccountKeyAuthentication SourceGoogleSheetsAuthenticationType = "source-google-sheets_Service Account Key Authentication"
)

// SourceGoogleSheetsAuthentication - Credentials for connecting to the Google Sheets API
type SourceGoogleSheetsAuthentication struct {
	SourceGoogleSheetsAuthenticateViaGoogleOAuth      *SourceGoogleSheetsAuthenticateViaGoogleOAuth      `queryParam:"inline"`
	SourceGoogleSheetsServiceAccountKeyAuthentication *SourceGoogleSheetsServiceAccountKeyAuthentication `queryParam:"inline"`

	Type SourceGoogleSheetsAuthenticationType
}

func CreateSourceGoogleSheetsAuthenticationSourceGoogleSheetsAuthenticateViaGoogleOAuth(sourceGoogleSheetsAuthenticateViaGoogleOAuth SourceGoogleSheetsAuthenticateViaGoogleOAuth) SourceGoogleSheetsAuthentication {
	typ := SourceGoogleSheetsAuthenticationTypeSourceGoogleSheetsAuthenticateViaGoogleOAuth

	return SourceGoogleSheetsAuthentication{
		SourceGoogleSheetsAuthenticateViaGoogleOAuth: &sourceGoogleSheetsAuthenticateViaGoogleOAuth,
		Type: typ,
	}
}

func CreateSourceGoogleSheetsAuthenticationSourceGoogleSheetsServiceAccountKeyAuthentication(sourceGoogleSheetsServiceAccountKeyAuthentication SourceGoogleSheetsServiceAccountKeyAuthentication) SourceGoogleSheetsAuthentication {
	typ := SourceGoogleSheetsAuthenticationTypeSourceGoogleSheetsServiceAccountKeyAuthentication

	return SourceGoogleSheetsAuthentication{
		SourceGoogleSheetsServiceAccountKeyAuthentication: &sourceGoogleSheetsServiceAccountKeyAuthentication,
		Type: typ,
	}
}

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

	var sourceGoogleSheetsServiceAccountKeyAuthentication SourceGoogleSheetsServiceAccountKeyAuthentication = SourceGoogleSheetsServiceAccountKeyAuthentication{}
	if err := utils.UnmarshalJSON(data, &sourceGoogleSheetsServiceAccountKeyAuthentication, "", true, true); err == nil {
		u.SourceGoogleSheetsServiceAccountKeyAuthentication = &sourceGoogleSheetsServiceAccountKeyAuthentication
		u.Type = SourceGoogleSheetsAuthenticationTypeSourceGoogleSheetsServiceAccountKeyAuthentication
		return nil
	}

	var sourceGoogleSheetsAuthenticateViaGoogleOAuth SourceGoogleSheetsAuthenticateViaGoogleOAuth = SourceGoogleSheetsAuthenticateViaGoogleOAuth{}
	if err := utils.UnmarshalJSON(data, &sourceGoogleSheetsAuthenticateViaGoogleOAuth, "", true, true); err == nil {
		u.SourceGoogleSheetsAuthenticateViaGoogleOAuth = &sourceGoogleSheetsAuthenticateViaGoogleOAuth
		u.Type = SourceGoogleSheetsAuthenticationTypeSourceGoogleSheetsAuthenticateViaGoogleOAuth
		return nil
	}

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

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

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

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

type StreamNameOverrides struct {
	// The name you want this stream to appear as in Airbyte and your destination.
	CustomStreamName string `json:"custom_stream_name"`
	// The exact name of the sheet/tab in your Google Spreadsheet.
	SourceStreamName string `json:"source_stream_name"`
}

func (o *StreamNameOverrides) GetCustomStreamName() string {
	if o == nil {
		return ""
	}
	return o.CustomStreamName
}

func (o *StreamNameOverrides) GetSourceStreamName() string {
	if o == nil {
		return ""
	}
	return o.SourceStreamName
}

type GoogleSheets string

const (
	GoogleSheetsGoogleSheets GoogleSheets = "google-sheets"
)

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

type SourceGoogleSheets struct {
	// Allows column names to start with numbers. Example: "50th Percentile" → "50_th_percentile" This option will only work if "Convert Column Names to SQL-Compliant Format (names_conversion)" is enabled.
	AllowLeadingNumbers *bool `default:"false" json:"allow_leading_numbers"`
	// Default value is 1000000. An integer representing row batch size for each sent request to Google Sheets API. Row batch size means how many rows are processed from the google sheet, for example default value 1000000 would process rows 2-1000002, then 1000003-2000003 and so on. Based on <a href='https://developers.google.com/sheets/api/limits'>Google Sheets API limits documentation</a>, it is possible to send up to 300 requests per minute, but each individual request has to be processed under 180 seconds, otherwise the request returns a timeout error. In regards to this information, consider network speed and number of columns of the google sheet when deciding a batch_size value.
	BatchSize *int64 `default:"1000000" json:"batch_size"`
	// Combines adjacent letters and numbers. Example: "Q3 2023" → "q3_2023" This option will only work if "Convert Column Names to SQL-Compliant Format (names_conversion)" is enabled.
	CombineLetterNumberPairs *bool `default:"false" json:"combine_letter_number_pairs"`
	// Combines adjacent numbers and words. Example: "50th Percentile?" → "_50th_percentile_" This option will only work if "Convert Column Names to SQL-Compliant Format (names_conversion)" is enabled.
	CombineNumberWordPairs *bool `default:"false" json:"combine_number_word_pairs"`
	// Credentials for connecting to the Google Sheets API
	Credentials SourceGoogleSheetsAuthentication `json:"credentials"`
	// Converts column names to a SQL-compliant format (snake_case, lowercase, etc). If enabled, you can further customize the sanitization using the options below.
	NamesConversion *bool `default:"false" json:"names_conversion"`
	// Removes leading and trailing underscores from column names. Does not remove leading underscores from column names that start with a number. Example: "50th Percentile? "→ "_50_th_percentile" This option will only work if "Convert Column Names to SQL-Compliant Format (names_conversion)" is enabled.
	RemoveLeadingTrailingUnderscores *bool `default:"false" json:"remove_leading_trailing_underscores"`
	// Removes all special characters from column names. Example: "Example ID*" → "example_id" This option will only work if "Convert Column Names to SQL-Compliant Format (names_conversion)" is enabled.
	RemoveSpecialCharacters *bool `default:"false" json:"remove_special_characters"`
	// Enter the link to the Google spreadsheet you want to sync. To copy the link, click the 'Share' button in the top-right corner of the spreadsheet, then click 'Copy link'.
	SpreadsheetID string `json:"spreadsheet_id"`
	// **Overridden streams will default to Sync Mode: Full Refresh (Append), which does not support primary keys. If you want to use primary keys and deduplication, update the sync mode to "Full Refresh | Overwrite + Deduped" in your connection settings.**
	// Allows you to rename streams (Google Sheet tab names) as they appear in Airbyte.
	// Each item should be an object with a `source_stream_name` (the exact name of the sheet/tab in your spreadsheet)  and a `custom_stream_name` (the name you want it to appear as in Airbyte and the destination).
	// If a `source_stream_name` is not found in your spreadsheet, it will be ignored and the default name will be used. This feature only affects stream (sheet/tab) names, not field/column names.
	// If you want to rename fields or column names, you can do so using the Airbyte Mappings feature after your connection is created. See the Airbyte documentation for more details on how to use Mappings.
	// Examples:
	//   - To rename a sheet called "Sheet1" to "sales_data", and "2024 Q1" to "q1_2024":
	//     [
	//       { "source_stream_name": "Sheet1", "custom_stream_name": "sales_data" },
	//       { "source_stream_name": "2024 Q1", "custom_stream_name": "q1_2024" }
	//     ]
	//   - If you do not wish to rename any streams, leave this blank.
	StreamNameOverrides []StreamNameOverrides `json:"stream_name_overrides,omitempty"`
	sourceType          GoogleSheets          `const:"google-sheets" json:"sourceType"`
}

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

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

func (o *SourceGoogleSheets) GetAllowLeadingNumbers() *bool {
	if o == nil {
		return nil
	}
	return o.AllowLeadingNumbers
}

func (o *SourceGoogleSheets) GetBatchSize() *int64 {
	if o == nil {
		return nil
	}
	return o.BatchSize
}

func (o *SourceGoogleSheets) GetCombineLetterNumberPairs() *bool {
	if o == nil {
		return nil
	}
	return o.CombineLetterNumberPairs
}

func (o *SourceGoogleSheets) GetCombineNumberWordPairs() *bool {
	if o == nil {
		return nil
	}
	return o.CombineNumberWordPairs
}

func (o *SourceGoogleSheets) GetCredentials() SourceGoogleSheetsAuthentication {
	if o == nil {
		return SourceGoogleSheetsAuthentication{}
	}
	return o.Credentials
}

func (o *SourceGoogleSheets) GetNamesConversion() *bool {
	if o == nil {
		return nil
	}
	return o.NamesConversion
}

func (o *SourceGoogleSheets) GetRemoveLeadingTrailingUnderscores() *bool {
	if o == nil {
		return nil
	}
	return o.RemoveLeadingTrailingUnderscores
}

func (o *SourceGoogleSheets) GetRemoveSpecialCharacters() *bool {
	if o == nil {
		return nil
	}
	return o.RemoveSpecialCharacters
}

func (o *SourceGoogleSheets) GetSpreadsheetID() string {
	if o == nil {
		return ""
	}
	return o.SpreadsheetID
}

func (o *SourceGoogleSheets) GetStreamNameOverrides() []StreamNameOverrides {
	if o == nil {
		return nil
	}
	return o.StreamNameOverrides
}

func (o *SourceGoogleSheets) GetSourceType() GoogleSheets {
	return GoogleSheetsGoogleSheets
}
