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

const (
	SourceGithubUpdateSchemasOptionTitlePatCredentials SourceGithubUpdateSchemasOptionTitle = "PAT Credentials"
)

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

type SourceGithubUpdatePersonalAccessToken struct {
	optionTitle *SourceGithubUpdateSchemasOptionTitle `const:"PAT Credentials" json:"option_title,omitempty"`
	// Log into GitHub and then generate a <a href="https://github.com/settings/tokens">personal access token</a>. To load balance your API quota consumption across multiple API tokens, input multiple tokens separated with ","
	PersonalAccessToken string `json:"personal_access_token"`
}

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

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

func (o *SourceGithubUpdatePersonalAccessToken) GetOptionTitle() *SourceGithubUpdateSchemasOptionTitle {
	return SourceGithubUpdateSchemasOptionTitlePatCredentials.ToPointer()
}

func (o *SourceGithubUpdatePersonalAccessToken) GetPersonalAccessToken() string {
	if o == nil {
		return ""
	}
	return o.PersonalAccessToken
}

type SourceGithubUpdateOptionTitle string

const (
	SourceGithubUpdateOptionTitleOAuthCredentials SourceGithubUpdateOptionTitle = "OAuth Credentials"
)

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

type SourceGithubUpdateOAuth struct {
	// OAuth access token
	AccessToken string `json:"access_token"`
	// OAuth Client Id
	ClientID *string `json:"client_id,omitempty"`
	// OAuth Client secret
	ClientSecret *string                        `json:"client_secret,omitempty"`
	optionTitle  *SourceGithubUpdateOptionTitle `const:"OAuth Credentials" json:"option_title,omitempty"`
}

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

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

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

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

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

func (o *SourceGithubUpdateOAuth) GetOptionTitle() *SourceGithubUpdateOptionTitle {
	return SourceGithubUpdateOptionTitleOAuthCredentials.ToPointer()
}

type SourceGithubUpdateAuthenticationType string

const (
	SourceGithubUpdateAuthenticationTypeSourceGithubUpdateOAuth               SourceGithubUpdateAuthenticationType = "source-github-update_OAuth"
	SourceGithubUpdateAuthenticationTypeSourceGithubUpdatePersonalAccessToken SourceGithubUpdateAuthenticationType = "source-github-update_Personal Access Token"
)

// SourceGithubUpdateAuthentication - Choose how to authenticate to GitHub
type SourceGithubUpdateAuthentication struct {
	SourceGithubUpdateOAuth               *SourceGithubUpdateOAuth               `queryParam:"inline"`
	SourceGithubUpdatePersonalAccessToken *SourceGithubUpdatePersonalAccessToken `queryParam:"inline"`

	Type SourceGithubUpdateAuthenticationType
}

func CreateSourceGithubUpdateAuthenticationSourceGithubUpdateOAuth(sourceGithubUpdateOAuth SourceGithubUpdateOAuth) SourceGithubUpdateAuthentication {
	typ := SourceGithubUpdateAuthenticationTypeSourceGithubUpdateOAuth

	return SourceGithubUpdateAuthentication{
		SourceGithubUpdateOAuth: &sourceGithubUpdateOAuth,
		Type:                    typ,
	}
}

func CreateSourceGithubUpdateAuthenticationSourceGithubUpdatePersonalAccessToken(sourceGithubUpdatePersonalAccessToken SourceGithubUpdatePersonalAccessToken) SourceGithubUpdateAuthentication {
	typ := SourceGithubUpdateAuthenticationTypeSourceGithubUpdatePersonalAccessToken

	return SourceGithubUpdateAuthentication{
		SourceGithubUpdatePersonalAccessToken: &sourceGithubUpdatePersonalAccessToken,
		Type:                                  typ,
	}
}

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

	var sourceGithubUpdatePersonalAccessToken SourceGithubUpdatePersonalAccessToken = SourceGithubUpdatePersonalAccessToken{}
	if err := utils.UnmarshalJSON(data, &sourceGithubUpdatePersonalAccessToken, "", true, true); err == nil {
		u.SourceGithubUpdatePersonalAccessToken = &sourceGithubUpdatePersonalAccessToken
		u.Type = SourceGithubUpdateAuthenticationTypeSourceGithubUpdatePersonalAccessToken
		return nil
	}

	var sourceGithubUpdateOAuth SourceGithubUpdateOAuth = SourceGithubUpdateOAuth{}
	if err := utils.UnmarshalJSON(data, &sourceGithubUpdateOAuth, "", true, true); err == nil {
		u.SourceGithubUpdateOAuth = &sourceGithubUpdateOAuth
		u.Type = SourceGithubUpdateAuthenticationTypeSourceGithubUpdateOAuth
		return nil
	}

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

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

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

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

type SourceGithubUpdate struct {
	// Please enter your basic URL from self-hosted GitHub instance or leave it empty to use GitHub.
	APIURL *string `default:"https://api.github.com/" json:"api_url"`
	// List of GitHub repository branches to pull commits for, e.g. `airbytehq/airbyte/master`. If no branches are specified for a repository, the default branch will be pulled.
	Branches []string `json:"branches,omitempty"`
	// Choose how to authenticate to GitHub
	Credentials SourceGithubUpdateAuthentication `json:"credentials"`
	// Max Waiting Time for rate limit. Set higher value to wait till rate limits will be resetted to continue sync
	MaxWaitingTime *int64 `default:"10" json:"max_waiting_time"`
	// List of GitHub organizations/repositories, e.g. `airbytehq/airbyte` for single repository, `airbytehq/*` for get all repositories from organization and `airbytehq/a* for matching multiple repositories by pattern.
	Repositories []string `json:"repositories"`
	// The date from which you'd like to replicate data from GitHub in the format YYYY-MM-DDT00:00:00Z. If the date is not set, all data will be replicated.  For the streams which support this configuration, only data generated on or after the start date will be replicated. This field doesn't apply to all streams, see the <a href="https://docs.airbyte.com/integrations/sources/github">docs</a> for more info
	StartDate *time.Time `json:"start_date,omitempty"`
}

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

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

func (o *SourceGithubUpdate) GetAPIURL() *string {
	if o == nil {
		return nil
	}
	return o.APIURL
}

func (o *SourceGithubUpdate) GetBranches() []string {
	if o == nil {
		return nil
	}
	return o.Branches
}

func (o *SourceGithubUpdate) GetCredentials() SourceGithubUpdateAuthentication {
	if o == nil {
		return SourceGithubUpdateAuthentication{}
	}
	return o.Credentials
}

func (o *SourceGithubUpdate) GetMaxWaitingTime() *int64 {
	if o == nil {
		return nil
	}
	return o.MaxWaitingTime
}

func (o *SourceGithubUpdate) GetRepositories() []string {
	if o == nil {
		return []string{}
	}
	return o.Repositories
}

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