package storage

// Code generated by cdproto-gen. DO NOT EDIT.

import (
	"fmt"
	"strings"

	"github.com/chromedp/cdproto/cdp"
	"github.com/chromedp/cdproto/target"
)

// SerializedStorageKey [no description].
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Storage#type-SerializedStorageKey
type SerializedStorageKey string

// String returns the SerializedStorageKey as string value.
func (t SerializedStorageKey) String() string {
	return string(t)
}

// Type enum of possible storage types.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Storage#type-StorageType
type Type string

// String returns the Type as string value.
func (t Type) String() string {
	return string(t)
}

// Type values.
const (
	TypeCookies        Type = "cookies"
	TypeFileSystems    Type = "file_systems"
	TypeIndexeddb      Type = "indexeddb"
	TypeLocalStorage   Type = "local_storage"
	TypeShaderCache    Type = "shader_cache"
	TypeWebsql         Type = "websql"
	TypeServiceWorkers Type = "service_workers"
	TypeCacheStorage   Type = "cache_storage"
	TypeSharedStorage  Type = "shared_storage"
	TypeStorageBuckets Type = "storage_buckets"
	TypeAll            Type = "all"
	TypeOther          Type = "other"
)

// UnmarshalJSON satisfies [json.Unmarshaler].
func (t *Type) UnmarshalJSON(buf []byte) error {
	s := string(buf)
	s = strings.TrimSuffix(strings.TrimPrefix(s, `"`), `"`)

	switch Type(s) {
	case TypeCookies:
		*t = TypeCookies
	case TypeFileSystems:
		*t = TypeFileSystems
	case TypeIndexeddb:
		*t = TypeIndexeddb
	case TypeLocalStorage:
		*t = TypeLocalStorage
	case TypeShaderCache:
		*t = TypeShaderCache
	case TypeWebsql:
		*t = TypeWebsql
	case TypeServiceWorkers:
		*t = TypeServiceWorkers
	case TypeCacheStorage:
		*t = TypeCacheStorage
	case TypeSharedStorage:
		*t = TypeSharedStorage
	case TypeStorageBuckets:
		*t = TypeStorageBuckets
	case TypeAll:
		*t = TypeAll
	case TypeOther:
		*t = TypeOther
	default:
		return fmt.Errorf("unknown Type value: %v", s)
	}
	return nil
}

// UsageForType usage for a storage type.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Storage#type-UsageForType
type UsageForType struct {
	StorageType Type    `json:"storageType"` // Name of storage type.
	Usage       float64 `json:"usage"`       // Storage usage (bytes).
}

// TrustTokens pair of issuer origin and number of available (signed, but not
// used) Trust Tokens from that issuer.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Storage#type-TrustTokens
type TrustTokens struct {
	IssuerOrigin string  `json:"issuerOrigin"`
	Count        float64 `json:"count"`
}

// SharedStorageAccessScope enum of shared storage access scopes.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Storage#type-SharedStorageAccessScope
type SharedStorageAccessScope string

// String returns the SharedStorageAccessScope as string value.
func (t SharedStorageAccessScope) String() string {
	return string(t)
}

// SharedStorageAccessScope values.
const (
	SharedStorageAccessScopeWindow               SharedStorageAccessScope = "window"
	SharedStorageAccessScopeSharedStorageWorklet SharedStorageAccessScope = "sharedStorageWorklet"
	SharedStorageAccessScopeHeader               SharedStorageAccessScope = "header"
)

// UnmarshalJSON satisfies [json.Unmarshaler].
func (t *SharedStorageAccessScope) UnmarshalJSON(buf []byte) error {
	s := string(buf)
	s = strings.TrimSuffix(strings.TrimPrefix(s, `"`), `"`)

	switch SharedStorageAccessScope(s) {
	case SharedStorageAccessScopeWindow:
		*t = SharedStorageAccessScopeWindow
	case SharedStorageAccessScopeSharedStorageWorklet:
		*t = SharedStorageAccessScopeSharedStorageWorklet
	case SharedStorageAccessScopeHeader:
		*t = SharedStorageAccessScopeHeader
	default:
		return fmt.Errorf("unknown SharedStorageAccessScope value: %v", s)
	}
	return nil
}

// SharedStorageAccessMethod enum of shared storage access methods.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Storage#type-SharedStorageAccessMethod
type SharedStorageAccessMethod string

// String returns the SharedStorageAccessMethod as string value.
func (t SharedStorageAccessMethod) String() string {
	return string(t)
}

// SharedStorageAccessMethod values.
const (
	SharedStorageAccessMethodAddModule       SharedStorageAccessMethod = "addModule"
	SharedStorageAccessMethodCreateWorklet   SharedStorageAccessMethod = "createWorklet"
	SharedStorageAccessMethodSelectURL       SharedStorageAccessMethod = "selectURL"
	SharedStorageAccessMethodRun             SharedStorageAccessMethod = "run"
	SharedStorageAccessMethodBatchUpdate     SharedStorageAccessMethod = "batchUpdate"
	SharedStorageAccessMethodSet             SharedStorageAccessMethod = "set"
	SharedStorageAccessMethodAppend          SharedStorageAccessMethod = "append"
	SharedStorageAccessMethodDelete          SharedStorageAccessMethod = "delete"
	SharedStorageAccessMethodClear           SharedStorageAccessMethod = "clear"
	SharedStorageAccessMethodGet             SharedStorageAccessMethod = "get"
	SharedStorageAccessMethodKeys            SharedStorageAccessMethod = "keys"
	SharedStorageAccessMethodValues          SharedStorageAccessMethod = "values"
	SharedStorageAccessMethodEntries         SharedStorageAccessMethod = "entries"
	SharedStorageAccessMethodLength          SharedStorageAccessMethod = "length"
	SharedStorageAccessMethodRemainingBudget SharedStorageAccessMethod = "remainingBudget"
)

// UnmarshalJSON satisfies [json.Unmarshaler].
func (t *SharedStorageAccessMethod) UnmarshalJSON(buf []byte) error {
	s := string(buf)
	s = strings.TrimSuffix(strings.TrimPrefix(s, `"`), `"`)

	switch SharedStorageAccessMethod(s) {
	case SharedStorageAccessMethodAddModule:
		*t = SharedStorageAccessMethodAddModule
	case SharedStorageAccessMethodCreateWorklet:
		*t = SharedStorageAccessMethodCreateWorklet
	case SharedStorageAccessMethodSelectURL:
		*t = SharedStorageAccessMethodSelectURL
	case SharedStorageAccessMethodRun:
		*t = SharedStorageAccessMethodRun
	case SharedStorageAccessMethodBatchUpdate:
		*t = SharedStorageAccessMethodBatchUpdate
	case SharedStorageAccessMethodSet:
		*t = SharedStorageAccessMethodSet
	case SharedStorageAccessMethodAppend:
		*t = SharedStorageAccessMethodAppend
	case SharedStorageAccessMethodDelete:
		*t = SharedStorageAccessMethodDelete
	case SharedStorageAccessMethodClear:
		*t = SharedStorageAccessMethodClear
	case SharedStorageAccessMethodGet:
		*t = SharedStorageAccessMethodGet
	case SharedStorageAccessMethodKeys:
		*t = SharedStorageAccessMethodKeys
	case SharedStorageAccessMethodValues:
		*t = SharedStorageAccessMethodValues
	case SharedStorageAccessMethodEntries:
		*t = SharedStorageAccessMethodEntries
	case SharedStorageAccessMethodLength:
		*t = SharedStorageAccessMethodLength
	case SharedStorageAccessMethodRemainingBudget:
		*t = SharedStorageAccessMethodRemainingBudget
	default:
		return fmt.Errorf("unknown SharedStorageAccessMethod value: %v", s)
	}
	return nil
}

// SharedStorageEntry struct for a single key-value pair in an origin's
// shared storage.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Storage#type-SharedStorageEntry
type SharedStorageEntry struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

// SharedStorageMetadata details for an origin's shared storage.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Storage#type-SharedStorageMetadata
type SharedStorageMetadata struct {
	CreationTime    *cdp.TimeSinceEpoch `json:"creationTime"`    // Time when the origin's shared storage was last created.
	Length          int64               `json:"length"`          // Number of key-value pairs stored in origin's shared storage.
	RemainingBudget float64             `json:"remainingBudget"` // Current amount of bits of entropy remaining in the navigation budget.
	BytesUsed       int64               `json:"bytesUsed"`       // Total number of bytes stored as key-value pairs in origin's shared storage.
}

// SharedStoragePrivateAggregationConfig represents a dictionary object
// passed in as privateAggregationConfig to run or selectURL.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Storage#type-SharedStoragePrivateAggregationConfig
type SharedStoragePrivateAggregationConfig struct {
	AggregationCoordinatorOrigin string `json:"aggregationCoordinatorOrigin,omitempty,omitzero"` // The chosen aggregation service deployment.
	ContextID                    string `json:"contextId,omitempty,omitzero"`                    // The context ID provided.
	FilteringIDMaxBytes          int64  `json:"filteringIdMaxBytes"`                             // Configures the maximum size allowed for filtering IDs.
	MaxContributions             int64  `json:"maxContributions,omitempty,omitzero"`             // The limit on the number of contributions in the final report.
}

// SharedStorageReportingMetadata pair of reporting metadata details for a
// candidate URL for selectURL().
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Storage#type-SharedStorageReportingMetadata
type SharedStorageReportingMetadata struct {
	EventType    string `json:"eventType"`
	ReportingURL string `json:"reportingUrl"`
}

// SharedStorageURLWithMetadata bundles a candidate URL with its reporting
// metadata.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Storage#type-SharedStorageUrlWithMetadata
type SharedStorageURLWithMetadata struct {
	URL               string                            `json:"url"`               // Spec of candidate URL.
	ReportingMetadata []*SharedStorageReportingMetadata `json:"reportingMetadata"` // Any associated reporting metadata.
}

// SharedStorageAccessParams bundles the parameters for shared storage access
// events whose presence/absence can vary according to SharedStorageAccessType.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Storage#type-SharedStorageAccessParams
type SharedStorageAccessParams struct {
	ScriptSourceURL          string                                 `json:"scriptSourceUrl,omitempty,omitzero"`          // Spec of the module script URL. Present only for SharedStorageAccessMethods: addModule and createWorklet.
	DataOrigin               string                                 `json:"dataOrigin,omitempty,omitzero"`               // String denoting "context-origin", "script-origin", or a custom origin to be used as the worklet's data origin. Present only for SharedStorageAccessMethod: createWorklet.
	OperationName            string                                 `json:"operationName,omitempty,omitzero"`            // Name of the registered operation to be run. Present only for SharedStorageAccessMethods: run and selectURL.
	OperationID              string                                 `json:"operationId,omitempty,omitzero"`              // ID of the operation call. Present only for SharedStorageAccessMethods: run and selectURL.
	KeepAlive                bool                                   `json:"keepAlive"`                                   // Whether or not to keep the worket alive for future run or selectURL calls. Present only for SharedStorageAccessMethods: run and selectURL.
	PrivateAggregationConfig *SharedStoragePrivateAggregationConfig `json:"privateAggregationConfig,omitempty,omitzero"` // Configures the private aggregation options. Present only for SharedStorageAccessMethods: run and selectURL.
	SerializedData           string                                 `json:"serializedData,omitempty,omitzero"`           // The operation's serialized data in bytes (converted to a string). Present only for SharedStorageAccessMethods: run and selectURL. TODO(crbug.com/401011862): Consider updating this parameter to binary.
	URLsWithMetadata         []*SharedStorageURLWithMetadata        `json:"urlsWithMetadata,omitempty,omitzero"`         // Array of candidate URLs' specs, along with any associated metadata. Present only for SharedStorageAccessMethod: selectURL.
	UrnUUID                  string                                 `json:"urnUuid,omitempty,omitzero"`                  // Spec of the URN:UUID generated for a selectURL call. Present only for SharedStorageAccessMethod: selectURL.
	Key                      string                                 `json:"key,omitempty,omitzero"`                      // Key for a specific entry in an origin's shared storage. Present only for SharedStorageAccessMethods: set, append, delete, and get.
	Value                    string                                 `json:"value,omitempty,omitzero"`                    // Value for a specific entry in an origin's shared storage. Present only for SharedStorageAccessMethods: set and append.
	IgnoreIfPresent          bool                                   `json:"ignoreIfPresent"`                             // Whether or not to set an entry for a key if that key is already present. Present only for SharedStorageAccessMethod: set.
	WorkletOrdinal           int64                                  `json:"workletOrdinal,omitempty,omitzero"`           // A number denoting the (0-based) order of the worklet's creation relative to all other shared storage worklets created by documents using the current storage partition. Present only for SharedStorageAccessMethods: addModule, createWorklet.
	WorkletTargetID          target.ID                              `json:"workletTargetId,omitempty,omitzero"`          // Hex representation of the DevTools token used as the TargetID for the associated shared storage worklet. Present only for SharedStorageAccessMethods: addModule, createWorklet, run, selectURL, and any other SharedStorageAccessMethod when the SharedStorageAccessScope is sharedStorageWorklet.
	WithLock                 string                                 `json:"withLock,omitempty,omitzero"`                 // Name of the lock to be acquired, if present. Optionally present only for SharedStorageAccessMethods: batchUpdate, set, append, delete, and clear.
	BatchUpdateID            string                                 `json:"batchUpdateId,omitempty,omitzero"`            // If the method has been called as part of a batchUpdate, then this number identifies the batch to which it belongs. Optionally present only for SharedStorageAccessMethods: batchUpdate (required), set, append, delete, and clear.
	BatchSize                int64                                  `json:"batchSize,omitempty,omitzero"`                // Number of modifier methods sent in batch. Present only for SharedStorageAccessMethod: batchUpdate.
}

// BucketsDurability [no description].
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Storage#type-StorageBucketsDurability
type BucketsDurability string

// String returns the BucketsDurability as string value.
func (t BucketsDurability) String() string {
	return string(t)
}

// BucketsDurability values.
const (
	BucketsDurabilityRelaxed BucketsDurability = "relaxed"
	BucketsDurabilityStrict  BucketsDurability = "strict"
)

// UnmarshalJSON satisfies [json.Unmarshaler].
func (t *BucketsDurability) UnmarshalJSON(buf []byte) error {
	s := string(buf)
	s = strings.TrimSuffix(strings.TrimPrefix(s, `"`), `"`)

	switch BucketsDurability(s) {
	case BucketsDurabilityRelaxed:
		*t = BucketsDurabilityRelaxed
	case BucketsDurabilityStrict:
		*t = BucketsDurabilityStrict
	default:
		return fmt.Errorf("unknown BucketsDurability value: %v", s)
	}
	return nil
}

// Bucket [no description].
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Storage#type-StorageBucket
type Bucket struct {
	StorageKey SerializedStorageKey `json:"storageKey"`
	Name       string               `json:"name,omitempty,omitzero"` // If not specified, it is the default bucket of the storageKey.
}

// BucketInfo [no description].
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Storage#type-StorageBucketInfo
type BucketInfo struct {
	Bucket     *Bucket             `json:"bucket"`
	ID         string              `json:"id"`
	Expiration *cdp.TimeSinceEpoch `json:"expiration"`
	Quota      float64             `json:"quota"` // Storage quota (bytes).
	Persistent bool                `json:"persistent"`
	Durability BucketsDurability   `json:"durability"`
}

// RelatedWebsiteSet a single Related Website Set object.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Storage#type-RelatedWebsiteSet
type RelatedWebsiteSet struct {
	PrimarySites    []string `json:"primarySites"`    // The primary site of this set, along with the ccTLDs if there is any.
	AssociatedSites []string `json:"associatedSites"` // The associated sites of this set, along with the ccTLDs if there is any.
	ServiceSites    []string `json:"serviceSites"`    // The service sites of this set, along with the ccTLDs if there is any.
}
