// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package zero_trust

import (
	"context"
	"errors"
	"fmt"
	"net/http"
	"net/url"
	"slices"

	"github.com/cloudflare/cloudflare-go/v6/internal/apijson"
	"github.com/cloudflare/cloudflare-go/v6/internal/apiquery"
	"github.com/cloudflare/cloudflare-go/v6/internal/param"
	"github.com/cloudflare/cloudflare-go/v6/internal/requestconfig"
	"github.com/cloudflare/cloudflare-go/v6/option"
)

// DEXFleetStatusService contains methods and other services that help with
// interacting with the cloudflare API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewDEXFleetStatusService] method instead.
type DEXFleetStatusService struct {
	Options []option.RequestOption
	Devices *DEXFleetStatusDeviceService
}

// NewDEXFleetStatusService generates a new service that applies the given options
// to each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewDEXFleetStatusService(opts ...option.RequestOption) (r *DEXFleetStatusService) {
	r = &DEXFleetStatusService{}
	r.Options = opts
	r.Devices = NewDEXFleetStatusDeviceService(opts...)
	return
}

// List details for live (up to 60 minutes) devices using WARP
func (r *DEXFleetStatusService) Live(ctx context.Context, params DEXFleetStatusLiveParams, opts ...option.RequestOption) (res *DEXFleetStatusLiveResponse, err error) {
	var env DEXFleetStatusLiveResponseEnvelope
	opts = slices.Concat(r.Options, opts)
	if params.AccountID.Value == "" {
		err = errors.New("missing required account_id parameter")
		return
	}
	path := fmt.Sprintf("accounts/%s/dex/fleet-status/live", params.AccountID)
	err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, params, &env, opts...)
	if err != nil {
		return
	}
	res = &env.Result
	return
}

// List details for devices using WARP, up to 7 days
func (r *DEXFleetStatusService) OverTime(ctx context.Context, params DEXFleetStatusOverTimeParams, opts ...option.RequestOption) (res *DEXFleetStatusOverTimeResponse, err error) {
	var env DEXFleetStatusOverTimeResponseEnvelope
	opts = slices.Concat(r.Options, opts)
	if params.AccountID.Value == "" {
		err = errors.New("missing required account_id parameter")
		return
	}
	path := fmt.Sprintf("accounts/%s/dex/fleet-status/over-time", params.AccountID)
	err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, params, &env, opts...)
	if err != nil {
		return
	}
	res = &env.Result
	return
}

type LiveStat struct {
	// Number of unique devices
	UniqueDevicesTotal float64      `json:"uniqueDevicesTotal"`
	Value              string       `json:"value"`
	JSON               liveStatJSON `json:"-"`
}

// liveStatJSON contains the JSON metadata for the struct [LiveStat]
type liveStatJSON struct {
	UniqueDevicesTotal apijson.Field
	Value              apijson.Field
	raw                string
	ExtraFields        map[string]apijson.Field
}

func (r *LiveStat) UnmarshalJSON(data []byte) (err error) {
	return apijson.UnmarshalRoot(data, r)
}

func (r liveStatJSON) RawJSON() string {
	return r.raw
}

type DEXFleetStatusLiveResponse struct {
	DeviceStats DEXFleetStatusLiveResponseDeviceStats `json:"deviceStats"`
	JSON        dexFleetStatusLiveResponseJSON        `json:"-"`
}

// dexFleetStatusLiveResponseJSON contains the JSON metadata for the struct
// [DEXFleetStatusLiveResponse]
type dexFleetStatusLiveResponseJSON struct {
	DeviceStats apijson.Field
	raw         string
	ExtraFields map[string]apijson.Field
}

func (r *DEXFleetStatusLiveResponse) UnmarshalJSON(data []byte) (err error) {
	return apijson.UnmarshalRoot(data, r)
}

func (r dexFleetStatusLiveResponseJSON) RawJSON() string {
	return r.raw
}

type DEXFleetStatusLiveResponseDeviceStats struct {
	ByColo     []LiveStat `json:"byColo,nullable"`
	ByMode     []LiveStat `json:"byMode,nullable"`
	ByPlatform []LiveStat `json:"byPlatform,nullable"`
	ByStatus   []LiveStat `json:"byStatus,nullable"`
	ByVersion  []LiveStat `json:"byVersion,nullable"`
	// Number of unique devices
	UniqueDevicesTotal float64                                   `json:"uniqueDevicesTotal"`
	JSON               dexFleetStatusLiveResponseDeviceStatsJSON `json:"-"`
}

// dexFleetStatusLiveResponseDeviceStatsJSON contains the JSON metadata for the
// struct [DEXFleetStatusLiveResponseDeviceStats]
type dexFleetStatusLiveResponseDeviceStatsJSON struct {
	ByColo             apijson.Field
	ByMode             apijson.Field
	ByPlatform         apijson.Field
	ByStatus           apijson.Field
	ByVersion          apijson.Field
	UniqueDevicesTotal apijson.Field
	raw                string
	ExtraFields        map[string]apijson.Field
}

func (r *DEXFleetStatusLiveResponseDeviceStats) UnmarshalJSON(data []byte) (err error) {
	return apijson.UnmarshalRoot(data, r)
}

func (r dexFleetStatusLiveResponseDeviceStatsJSON) RawJSON() string {
	return r.raw
}

type DEXFleetStatusOverTimeResponse struct {
	DeviceStats DEXFleetStatusOverTimeResponseDeviceStats `json:"deviceStats"`
	JSON        dexFleetStatusOverTimeResponseJSON        `json:"-"`
}

// dexFleetStatusOverTimeResponseJSON contains the JSON metadata for the struct
// [DEXFleetStatusOverTimeResponse]
type dexFleetStatusOverTimeResponseJSON struct {
	DeviceStats apijson.Field
	raw         string
	ExtraFields map[string]apijson.Field
}

func (r *DEXFleetStatusOverTimeResponse) UnmarshalJSON(data []byte) (err error) {
	return apijson.UnmarshalRoot(data, r)
}

func (r dexFleetStatusOverTimeResponseJSON) RawJSON() string {
	return r.raw
}

type DEXFleetStatusOverTimeResponseDeviceStats struct {
	ByMode   []DEXFleetStatusOverTimeResponseDeviceStatsByMode   `json:"byMode"`
	ByStatus []DEXFleetStatusOverTimeResponseDeviceStatsByStatus `json:"byStatus"`
	// Number of unique devices
	UniqueDevicesTotal float64                                       `json:"uniqueDevicesTotal"`
	JSON               dexFleetStatusOverTimeResponseDeviceStatsJSON `json:"-"`
}

// dexFleetStatusOverTimeResponseDeviceStatsJSON contains the JSON metadata for the
// struct [DEXFleetStatusOverTimeResponseDeviceStats]
type dexFleetStatusOverTimeResponseDeviceStatsJSON struct {
	ByMode             apijson.Field
	ByStatus           apijson.Field
	UniqueDevicesTotal apijson.Field
	raw                string
	ExtraFields        map[string]apijson.Field
}

func (r *DEXFleetStatusOverTimeResponseDeviceStats) UnmarshalJSON(data []byte) (err error) {
	return apijson.UnmarshalRoot(data, r)
}

func (r dexFleetStatusOverTimeResponseDeviceStatsJSON) RawJSON() string {
	return r.raw
}

type DEXFleetStatusOverTimeResponseDeviceStatsByMode struct {
	// Timestamp in ISO format
	Timestamp string `json:"timestamp"`
	// Number of unique devices
	UniqueDevicesTotal float64                                             `json:"uniqueDevicesTotal"`
	Value              string                                              `json:"value"`
	JSON               dexFleetStatusOverTimeResponseDeviceStatsByModeJSON `json:"-"`
}

// dexFleetStatusOverTimeResponseDeviceStatsByModeJSON contains the JSON metadata
// for the struct [DEXFleetStatusOverTimeResponseDeviceStatsByMode]
type dexFleetStatusOverTimeResponseDeviceStatsByModeJSON struct {
	Timestamp          apijson.Field
	UniqueDevicesTotal apijson.Field
	Value              apijson.Field
	raw                string
	ExtraFields        map[string]apijson.Field
}

func (r *DEXFleetStatusOverTimeResponseDeviceStatsByMode) UnmarshalJSON(data []byte) (err error) {
	return apijson.UnmarshalRoot(data, r)
}

func (r dexFleetStatusOverTimeResponseDeviceStatsByModeJSON) RawJSON() string {
	return r.raw
}

type DEXFleetStatusOverTimeResponseDeviceStatsByStatus struct {
	// Timestamp in ISO format
	Timestamp string `json:"timestamp"`
	// Number of unique devices
	UniqueDevicesTotal float64                                               `json:"uniqueDevicesTotal"`
	Value              string                                                `json:"value"`
	JSON               dexFleetStatusOverTimeResponseDeviceStatsByStatusJSON `json:"-"`
}

// dexFleetStatusOverTimeResponseDeviceStatsByStatusJSON contains the JSON metadata
// for the struct [DEXFleetStatusOverTimeResponseDeviceStatsByStatus]
type dexFleetStatusOverTimeResponseDeviceStatsByStatusJSON struct {
	Timestamp          apijson.Field
	UniqueDevicesTotal apijson.Field
	Value              apijson.Field
	raw                string
	ExtraFields        map[string]apijson.Field
}

func (r *DEXFleetStatusOverTimeResponseDeviceStatsByStatus) UnmarshalJSON(data []byte) (err error) {
	return apijson.UnmarshalRoot(data, r)
}

func (r dexFleetStatusOverTimeResponseDeviceStatsByStatusJSON) RawJSON() string {
	return r.raw
}

type DEXFleetStatusLiveParams struct {
	AccountID param.Field[string] `path:"account_id,required"`
	// Number of minutes before current time
	SinceMinutes param.Field[float64] `query:"since_minutes,required"`
}

// URLQuery serializes [DEXFleetStatusLiveParams]'s query parameters as
// `url.Values`.
func (r DEXFleetStatusLiveParams) URLQuery() (v url.Values) {
	return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
		ArrayFormat:  apiquery.ArrayQueryFormatRepeat,
		NestedFormat: apiquery.NestedQueryFormatDots,
	})
}

type DEXFleetStatusLiveResponseEnvelope struct {
	Errors   []DEXFleetStatusLiveResponseEnvelopeErrors   `json:"errors,required"`
	Messages []DEXFleetStatusLiveResponseEnvelopeMessages `json:"messages,required"`
	// Whether the API call was successful.
	Success DEXFleetStatusLiveResponseEnvelopeSuccess `json:"success,required"`
	Result  DEXFleetStatusLiveResponse                `json:"result"`
	JSON    dexFleetStatusLiveResponseEnvelopeJSON    `json:"-"`
}

// dexFleetStatusLiveResponseEnvelopeJSON contains the JSON metadata for the struct
// [DEXFleetStatusLiveResponseEnvelope]
type dexFleetStatusLiveResponseEnvelopeJSON struct {
	Errors      apijson.Field
	Messages    apijson.Field
	Success     apijson.Field
	Result      apijson.Field
	raw         string
	ExtraFields map[string]apijson.Field
}

func (r *DEXFleetStatusLiveResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
	return apijson.UnmarshalRoot(data, r)
}

func (r dexFleetStatusLiveResponseEnvelopeJSON) RawJSON() string {
	return r.raw
}

type DEXFleetStatusLiveResponseEnvelopeErrors struct {
	Code             int64                                          `json:"code,required"`
	Message          string                                         `json:"message,required"`
	DocumentationURL string                                         `json:"documentation_url"`
	Source           DEXFleetStatusLiveResponseEnvelopeErrorsSource `json:"source"`
	JSON             dexFleetStatusLiveResponseEnvelopeErrorsJSON   `json:"-"`
}

// dexFleetStatusLiveResponseEnvelopeErrorsJSON contains the JSON metadata for the
// struct [DEXFleetStatusLiveResponseEnvelopeErrors]
type dexFleetStatusLiveResponseEnvelopeErrorsJSON struct {
	Code             apijson.Field
	Message          apijson.Field
	DocumentationURL apijson.Field
	Source           apijson.Field
	raw              string
	ExtraFields      map[string]apijson.Field
}

func (r *DEXFleetStatusLiveResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) {
	return apijson.UnmarshalRoot(data, r)
}

func (r dexFleetStatusLiveResponseEnvelopeErrorsJSON) RawJSON() string {
	return r.raw
}

type DEXFleetStatusLiveResponseEnvelopeErrorsSource struct {
	Pointer string                                             `json:"pointer"`
	JSON    dexFleetStatusLiveResponseEnvelopeErrorsSourceJSON `json:"-"`
}

// dexFleetStatusLiveResponseEnvelopeErrorsSourceJSON contains the JSON metadata
// for the struct [DEXFleetStatusLiveResponseEnvelopeErrorsSource]
type dexFleetStatusLiveResponseEnvelopeErrorsSourceJSON struct {
	Pointer     apijson.Field
	raw         string
	ExtraFields map[string]apijson.Field
}

func (r *DEXFleetStatusLiveResponseEnvelopeErrorsSource) UnmarshalJSON(data []byte) (err error) {
	return apijson.UnmarshalRoot(data, r)
}

func (r dexFleetStatusLiveResponseEnvelopeErrorsSourceJSON) RawJSON() string {
	return r.raw
}

type DEXFleetStatusLiveResponseEnvelopeMessages struct {
	Code             int64                                            `json:"code,required"`
	Message          string                                           `json:"message,required"`
	DocumentationURL string                                           `json:"documentation_url"`
	Source           DEXFleetStatusLiveResponseEnvelopeMessagesSource `json:"source"`
	JSON             dexFleetStatusLiveResponseEnvelopeMessagesJSON   `json:"-"`
}

// dexFleetStatusLiveResponseEnvelopeMessagesJSON contains the JSON metadata for
// the struct [DEXFleetStatusLiveResponseEnvelopeMessages]
type dexFleetStatusLiveResponseEnvelopeMessagesJSON struct {
	Code             apijson.Field
	Message          apijson.Field
	DocumentationURL apijson.Field
	Source           apijson.Field
	raw              string
	ExtraFields      map[string]apijson.Field
}

func (r *DEXFleetStatusLiveResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) {
	return apijson.UnmarshalRoot(data, r)
}

func (r dexFleetStatusLiveResponseEnvelopeMessagesJSON) RawJSON() string {
	return r.raw
}

type DEXFleetStatusLiveResponseEnvelopeMessagesSource struct {
	Pointer string                                               `json:"pointer"`
	JSON    dexFleetStatusLiveResponseEnvelopeMessagesSourceJSON `json:"-"`
}

// dexFleetStatusLiveResponseEnvelopeMessagesSourceJSON contains the JSON metadata
// for the struct [DEXFleetStatusLiveResponseEnvelopeMessagesSource]
type dexFleetStatusLiveResponseEnvelopeMessagesSourceJSON struct {
	Pointer     apijson.Field
	raw         string
	ExtraFields map[string]apijson.Field
}

func (r *DEXFleetStatusLiveResponseEnvelopeMessagesSource) UnmarshalJSON(data []byte) (err error) {
	return apijson.UnmarshalRoot(data, r)
}

func (r dexFleetStatusLiveResponseEnvelopeMessagesSourceJSON) RawJSON() string {
	return r.raw
}

// Whether the API call was successful.
type DEXFleetStatusLiveResponseEnvelopeSuccess bool

const (
	DEXFleetStatusLiveResponseEnvelopeSuccessTrue DEXFleetStatusLiveResponseEnvelopeSuccess = true
)

func (r DEXFleetStatusLiveResponseEnvelopeSuccess) IsKnown() bool {
	switch r {
	case DEXFleetStatusLiveResponseEnvelopeSuccessTrue:
		return true
	}
	return false
}

type DEXFleetStatusOverTimeParams struct {
	AccountID param.Field[string] `path:"account_id,required"`
	// Time range beginning in ISO format
	From param.Field[string] `query:"from,required"`
	// Time range end in ISO format
	To param.Field[string] `query:"to,required"`
	// Cloudflare colo
	Colo param.Field[string] `query:"colo"`
	// Device-specific ID, given as UUID v4
	DeviceID param.Field[string] `query:"device_id"`
}

// URLQuery serializes [DEXFleetStatusOverTimeParams]'s query parameters as
// `url.Values`.
func (r DEXFleetStatusOverTimeParams) URLQuery() (v url.Values) {
	return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
		ArrayFormat:  apiquery.ArrayQueryFormatRepeat,
		NestedFormat: apiquery.NestedQueryFormatDots,
	})
}

type DEXFleetStatusOverTimeResponseEnvelope struct {
	Errors   []DEXFleetStatusOverTimeResponseEnvelopeErrors   `json:"errors,required"`
	Messages []DEXFleetStatusOverTimeResponseEnvelopeMessages `json:"messages,required"`
	// Whether the API call was successful.
	Success    DEXFleetStatusOverTimeResponseEnvelopeSuccess    `json:"success,required"`
	Result     DEXFleetStatusOverTimeResponse                   `json:"result"`
	ResultInfo DEXFleetStatusOverTimeResponseEnvelopeResultInfo `json:"result_info"`
	JSON       dexFleetStatusOverTimeResponseEnvelopeJSON       `json:"-"`
}

// dexFleetStatusOverTimeResponseEnvelopeJSON contains the JSON metadata for the
// struct [DEXFleetStatusOverTimeResponseEnvelope]
type dexFleetStatusOverTimeResponseEnvelopeJSON struct {
	Errors      apijson.Field
	Messages    apijson.Field
	Success     apijson.Field
	Result      apijson.Field
	ResultInfo  apijson.Field
	raw         string
	ExtraFields map[string]apijson.Field
}

func (r *DEXFleetStatusOverTimeResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
	return apijson.UnmarshalRoot(data, r)
}

func (r dexFleetStatusOverTimeResponseEnvelopeJSON) RawJSON() string {
	return r.raw
}

type DEXFleetStatusOverTimeResponseEnvelopeErrors struct {
	Code             int64                                              `json:"code,required"`
	Message          string                                             `json:"message,required"`
	DocumentationURL string                                             `json:"documentation_url"`
	Source           DEXFleetStatusOverTimeResponseEnvelopeErrorsSource `json:"source"`
	JSON             dexFleetStatusOverTimeResponseEnvelopeErrorsJSON   `json:"-"`
}

// dexFleetStatusOverTimeResponseEnvelopeErrorsJSON contains the JSON metadata for
// the struct [DEXFleetStatusOverTimeResponseEnvelopeErrors]
type dexFleetStatusOverTimeResponseEnvelopeErrorsJSON struct {
	Code             apijson.Field
	Message          apijson.Field
	DocumentationURL apijson.Field
	Source           apijson.Field
	raw              string
	ExtraFields      map[string]apijson.Field
}

func (r *DEXFleetStatusOverTimeResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) {
	return apijson.UnmarshalRoot(data, r)
}

func (r dexFleetStatusOverTimeResponseEnvelopeErrorsJSON) RawJSON() string {
	return r.raw
}

type DEXFleetStatusOverTimeResponseEnvelopeErrorsSource struct {
	Pointer string                                                 `json:"pointer"`
	JSON    dexFleetStatusOverTimeResponseEnvelopeErrorsSourceJSON `json:"-"`
}

// dexFleetStatusOverTimeResponseEnvelopeErrorsSourceJSON contains the JSON
// metadata for the struct [DEXFleetStatusOverTimeResponseEnvelopeErrorsSource]
type dexFleetStatusOverTimeResponseEnvelopeErrorsSourceJSON struct {
	Pointer     apijson.Field
	raw         string
	ExtraFields map[string]apijson.Field
}

func (r *DEXFleetStatusOverTimeResponseEnvelopeErrorsSource) UnmarshalJSON(data []byte) (err error) {
	return apijson.UnmarshalRoot(data, r)
}

func (r dexFleetStatusOverTimeResponseEnvelopeErrorsSourceJSON) RawJSON() string {
	return r.raw
}

type DEXFleetStatusOverTimeResponseEnvelopeMessages struct {
	Code             int64                                                `json:"code,required"`
	Message          string                                               `json:"message,required"`
	DocumentationURL string                                               `json:"documentation_url"`
	Source           DEXFleetStatusOverTimeResponseEnvelopeMessagesSource `json:"source"`
	JSON             dexFleetStatusOverTimeResponseEnvelopeMessagesJSON   `json:"-"`
}

// dexFleetStatusOverTimeResponseEnvelopeMessagesJSON contains the JSON metadata
// for the struct [DEXFleetStatusOverTimeResponseEnvelopeMessages]
type dexFleetStatusOverTimeResponseEnvelopeMessagesJSON struct {
	Code             apijson.Field
	Message          apijson.Field
	DocumentationURL apijson.Field
	Source           apijson.Field
	raw              string
	ExtraFields      map[string]apijson.Field
}

func (r *DEXFleetStatusOverTimeResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) {
	return apijson.UnmarshalRoot(data, r)
}

func (r dexFleetStatusOverTimeResponseEnvelopeMessagesJSON) RawJSON() string {
	return r.raw
}

type DEXFleetStatusOverTimeResponseEnvelopeMessagesSource struct {
	Pointer string                                                   `json:"pointer"`
	JSON    dexFleetStatusOverTimeResponseEnvelopeMessagesSourceJSON `json:"-"`
}

// dexFleetStatusOverTimeResponseEnvelopeMessagesSourceJSON contains the JSON
// metadata for the struct [DEXFleetStatusOverTimeResponseEnvelopeMessagesSource]
type dexFleetStatusOverTimeResponseEnvelopeMessagesSourceJSON struct {
	Pointer     apijson.Field
	raw         string
	ExtraFields map[string]apijson.Field
}

func (r *DEXFleetStatusOverTimeResponseEnvelopeMessagesSource) UnmarshalJSON(data []byte) (err error) {
	return apijson.UnmarshalRoot(data, r)
}

func (r dexFleetStatusOverTimeResponseEnvelopeMessagesSourceJSON) RawJSON() string {
	return r.raw
}

// Whether the API call was successful.
type DEXFleetStatusOverTimeResponseEnvelopeSuccess bool

const (
	DEXFleetStatusOverTimeResponseEnvelopeSuccessTrue DEXFleetStatusOverTimeResponseEnvelopeSuccess = true
)

func (r DEXFleetStatusOverTimeResponseEnvelopeSuccess) IsKnown() bool {
	switch r {
	case DEXFleetStatusOverTimeResponseEnvelopeSuccessTrue:
		return true
	}
	return false
}

type DEXFleetStatusOverTimeResponseEnvelopeResultInfo struct {
	// Total number of results for the requested service.
	Count float64 `json:"count"`
	// Current page within paginated list of results.
	Page float64 `json:"page"`
	// Number of results per page of results.
	PerPage float64 `json:"per_page"`
	// Total results available without any search parameters.
	TotalCount float64                                              `json:"total_count"`
	JSON       dexFleetStatusOverTimeResponseEnvelopeResultInfoJSON `json:"-"`
}

// dexFleetStatusOverTimeResponseEnvelopeResultInfoJSON contains the JSON metadata
// for the struct [DEXFleetStatusOverTimeResponseEnvelopeResultInfo]
type dexFleetStatusOverTimeResponseEnvelopeResultInfoJSON struct {
	Count       apijson.Field
	Page        apijson.Field
	PerPage     apijson.Field
	TotalCount  apijson.Field
	raw         string
	ExtraFields map[string]apijson.Field
}

func (r *DEXFleetStatusOverTimeResponseEnvelopeResultInfo) UnmarshalJSON(data []byte) (err error) {
	return apijson.UnmarshalRoot(data, r)
}

func (r dexFleetStatusOverTimeResponseEnvelopeResultInfoJSON) RawJSON() string {
	return r.raw
}
