// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.

package shared

import (
	"encoding/json"
	"fmt"
	"github.com/airbytehq/terraform-provider-airbyte/internal/sdk/internal/utils"
)

// PeriodUsedForMostPopularStreams - Period of time (in days)
type PeriodUsedForMostPopularStreams int64

const (
	PeriodUsedForMostPopularStreamsOne    PeriodUsedForMostPopularStreams = 1
	PeriodUsedForMostPopularStreamsSeven  PeriodUsedForMostPopularStreams = 7
	PeriodUsedForMostPopularStreamsThirty PeriodUsedForMostPopularStreams = 30
)

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

// ShareTypeUsedForMostPopularSharedStream - Share Type
type ShareTypeUsedForMostPopularSharedStream string

const (
	ShareTypeUsedForMostPopularSharedStreamFacebook ShareTypeUsedForMostPopularSharedStream = "facebook"
)

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

type Nytimes string

const (
	NytimesNytimes Nytimes = "nytimes"
)

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

type SourceNytimes struct {
	// API Key
	APIKey string `json:"api_key"`
	// End date to stop the article retrieval (format YYYY-MM)
	EndDate *string `json:"end_date,omitempty"`
	// Period of time (in days)
	Period PeriodUsedForMostPopularStreams `json:"period"`
	// Share Type
	ShareType *ShareTypeUsedForMostPopularSharedStream `json:"share_type,omitempty"`
	// Start date to begin the article retrieval (format YYYY-MM)
	StartDate  string  `json:"start_date"`
	sourceType Nytimes `const:"nytimes" json:"sourceType"`
}

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

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

func (o *SourceNytimes) GetAPIKey() string {
	if o == nil {
		return ""
	}
	return o.APIKey
}

func (o *SourceNytimes) GetEndDate() *string {
	if o == nil {
		return nil
	}
	return o.EndDate
}

func (o *SourceNytimes) GetPeriod() PeriodUsedForMostPopularStreams {
	if o == nil {
		return PeriodUsedForMostPopularStreams(0)
	}
	return o.Period
}

func (o *SourceNytimes) GetShareType() *ShareTypeUsedForMostPopularSharedStream {
	if o == nil {
		return nil
	}
	return o.ShareType
}

func (o *SourceNytimes) GetStartDate() string {
	if o == nil {
		return ""
	}
	return o.StartDate
}

func (o *SourceNytimes) GetSourceType() Nytimes {
	return NytimesNytimes
}
