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

const (
	SourceWorkdayUpdateRESTRest SourceWorkdayUpdateREST = "REST"
)

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

type SourceWorkdayUpdateRESTAPIStreams struct {
	// Follow the instructions in the "OAuth 2.0 in Postman - API Client for Integrations" article in the Workday community docs to obtain access token.
	AccessToken string                  `json:"access_token"`
	authType    SourceWorkdayUpdateREST `const:"REST" json:"auth_type"`
	// Rows after this date will be synced, default 2 years ago.
	StartDate *time.Time `json:"start_date,omitempty"`
}

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

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

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

func (o *SourceWorkdayUpdateRESTAPIStreams) GetAuthType() SourceWorkdayUpdateREST {
	return SourceWorkdayUpdateRESTRest
}

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

type SourceWorkdayUpdateRAAS string

const (
	SourceWorkdayUpdateRAASRaas SourceWorkdayUpdateRAAS = "RAAS"
)

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

type SourceWorkdayUpdateReportBasedStreams struct {
	authType SourceWorkdayUpdateRAAS `const:"RAAS" json:"auth_type"`
	Password string                  `json:"password"`
	// Report IDs can be found by clicking the three dots on the right side of the report > Web Service > View URLs > in JSON url copy everything between Workday tenant/ and ?format=json.
	ReportIds []any  `json:"report_ids"`
	Username  string `json:"username"`
}

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

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

func (o *SourceWorkdayUpdateReportBasedStreams) GetAuthType() SourceWorkdayUpdateRAAS {
	return SourceWorkdayUpdateRAASRaas
}

func (o *SourceWorkdayUpdateReportBasedStreams) GetPassword() string {
	if o == nil {
		return ""
	}
	return o.Password
}

func (o *SourceWorkdayUpdateReportBasedStreams) GetReportIds() []any {
	if o == nil {
		return []any{}
	}
	return o.ReportIds
}

func (o *SourceWorkdayUpdateReportBasedStreams) GetUsername() string {
	if o == nil {
		return ""
	}
	return o.Username
}

type SourceWorkdayUpdateAuthenticationType string

const (
	SourceWorkdayUpdateAuthenticationTypeSourceWorkdayUpdateReportBasedStreams SourceWorkdayUpdateAuthenticationType = "source-workday-update_Report Based Streams"
	SourceWorkdayUpdateAuthenticationTypeSourceWorkdayUpdateRESTAPIStreams     SourceWorkdayUpdateAuthenticationType = "source-workday-update_REST API Streams"
)

// SourceWorkdayUpdateAuthentication - Report Based Streams and REST API Streams use different methods of Authentication. Choose streams type you want to sync and provide needed credentials for them.
type SourceWorkdayUpdateAuthentication struct {
	SourceWorkdayUpdateReportBasedStreams *SourceWorkdayUpdateReportBasedStreams `queryParam:"inline"`
	SourceWorkdayUpdateRESTAPIStreams     *SourceWorkdayUpdateRESTAPIStreams     `queryParam:"inline"`

	Type SourceWorkdayUpdateAuthenticationType
}

func CreateSourceWorkdayUpdateAuthenticationSourceWorkdayUpdateReportBasedStreams(sourceWorkdayUpdateReportBasedStreams SourceWorkdayUpdateReportBasedStreams) SourceWorkdayUpdateAuthentication {
	typ := SourceWorkdayUpdateAuthenticationTypeSourceWorkdayUpdateReportBasedStreams

	return SourceWorkdayUpdateAuthentication{
		SourceWorkdayUpdateReportBasedStreams: &sourceWorkdayUpdateReportBasedStreams,
		Type:                                  typ,
	}
}

func CreateSourceWorkdayUpdateAuthenticationSourceWorkdayUpdateRESTAPIStreams(sourceWorkdayUpdateRESTAPIStreams SourceWorkdayUpdateRESTAPIStreams) SourceWorkdayUpdateAuthentication {
	typ := SourceWorkdayUpdateAuthenticationTypeSourceWorkdayUpdateRESTAPIStreams

	return SourceWorkdayUpdateAuthentication{
		SourceWorkdayUpdateRESTAPIStreams: &sourceWorkdayUpdateRESTAPIStreams,
		Type:                              typ,
	}
}

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

	var sourceWorkdayUpdateRESTAPIStreams SourceWorkdayUpdateRESTAPIStreams = SourceWorkdayUpdateRESTAPIStreams{}
	if err := utils.UnmarshalJSON(data, &sourceWorkdayUpdateRESTAPIStreams, "", true, true); err == nil {
		u.SourceWorkdayUpdateRESTAPIStreams = &sourceWorkdayUpdateRESTAPIStreams
		u.Type = SourceWorkdayUpdateAuthenticationTypeSourceWorkdayUpdateRESTAPIStreams
		return nil
	}

	var sourceWorkdayUpdateReportBasedStreams SourceWorkdayUpdateReportBasedStreams = SourceWorkdayUpdateReportBasedStreams{}
	if err := utils.UnmarshalJSON(data, &sourceWorkdayUpdateReportBasedStreams, "", true, true); err == nil {
		u.SourceWorkdayUpdateReportBasedStreams = &sourceWorkdayUpdateReportBasedStreams
		u.Type = SourceWorkdayUpdateAuthenticationTypeSourceWorkdayUpdateReportBasedStreams
		return nil
	}

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

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

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

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

type SourceWorkdayUpdate struct {
	// Report Based Streams and REST API Streams use different methods of Authentication. Choose streams type you want to sync and provide needed credentials for them.
	Credentials SourceWorkdayUpdateAuthentication `json:"credentials"`
	Host        string                            `json:"host"`
	TenantID    string                            `json:"tenant_id"`
}

func (o *SourceWorkdayUpdate) GetCredentials() SourceWorkdayUpdateAuthentication {
	if o == nil {
		return SourceWorkdayUpdateAuthentication{}
	}
	return o.Credentials
}

func (o *SourceWorkdayUpdate) GetHost() string {
	if o == nil {
		return ""
	}
	return o.Host
}

func (o *SourceWorkdayUpdate) GetTenantID() string {
	if o == nil {
		return ""
	}
	return o.TenantID
}
