# frozen_string_literal: true

# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

# DO NOT EDIT! This file is generated by rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb.
# Regenerate with: `bazel run //rb/lib/selenium/webdriver:bidi-generate`

module Selenium
  module WebDriver
    class BiDi
      module Protocol
        # @api private
        # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
        # @see https://w3c.github.io/webdriver-bidi/#module-storage
        class Storage < Domain
          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#type-storage-PartitionKey
          PartitionKey = Serialization::Record.define(
            user_context: {wire_key: 'userContext', required: false, primitive: 'string'},
            source_origin: {wire_key: 'sourceOrigin', required: false, primitive: 'string'},
            extensible: true
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-storagecookiefilter
          CookieFilter = Serialization::Record.define(
            name: {wire_key: 'name', required: false, primitive: 'string'},
            value: {wire_key: 'value', required: false, ref: 'Network::BytesValue'},
            domain: {wire_key: 'domain', required: false, primitive: 'string'},
            path: {wire_key: 'path', required: false, primitive: 'string'},
            size: {wire_key: 'size', required: false, primitive: 'integer'},
            http_only: {wire_key: 'httpOnly', required: false, primitive: 'boolean'},
            secure: {wire_key: 'secure', required: false, primitive: 'boolean'},
            same_site: {wire_key: 'sameSite', required: false, enum: 'Network::SAME_SITE'},
            expiry: {wire_key: 'expiry', required: false, primitive: 'integer'},
            extensible: true
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-storagebrowsingcontextpartitiondescriptor
          BrowsingContextPartitionDescriptor = Serialization::Record.define(
            type: {fixed: 'context'},
            context: {wire_key: 'context', primitive: 'string'}
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-storagestoragekeypartitiondescriptor
          StorageKeyPartitionDescriptor = Serialization::Record.define(
            type: {fixed: 'storageKey'},
            user_context: {wire_key: 'userContext', required: false, primitive: 'string'},
            source_origin: {wire_key: 'sourceOrigin', required: false, primitive: 'string'},
            extensible: true
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-storagepartitiondescriptor
          class PartitionDescriptor < Serialization::Union
            discriminator 'type', {context: 'context', storage_key: 'storageKey'}
            variants(
              context: 'Storage::BrowsingContextPartitionDescriptor',
              storage_key: 'Storage::StorageKeyPartitionDescriptor'
            )
            object_only

            def self.context(**) = Storage::BrowsingContextPartitionDescriptor.new(**)
            def self.storage_key(**) = Storage::StorageKeyPartitionDescriptor.new(**)
          end

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-storagegetcookiesparameters
          GetCookiesParameters = Serialization::Record.define(
            filter: {wire_key: 'filter', required: false, ref: 'Storage::CookieFilter'},
            partition: {wire_key: 'partition', required: false, ref: 'Storage::PartitionDescriptor'}
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-storagegetcookiesresult
          GetCookiesResult = Serialization::Record.define(
            cookies: {wire_key: 'cookies', ref: 'Network::Cookie', list: true},
            partition_key: {wire_key: 'partitionKey', ref: 'Storage::PartitionKey'}
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-storagepartialcookie
          PartialCookie = Serialization::Record.define(
            name: {wire_key: 'name', primitive: 'string'},
            value: {wire_key: 'value', ref: 'Network::BytesValue'},
            domain: {wire_key: 'domain', primitive: 'string'},
            path: {wire_key: 'path', required: false, primitive: 'string'},
            http_only: {wire_key: 'httpOnly', required: false, primitive: 'boolean'},
            secure: {wire_key: 'secure', required: false, primitive: 'boolean'},
            same_site: {wire_key: 'sameSite', required: false, enum: 'Network::SAME_SITE'},
            expiry: {wire_key: 'expiry', required: false, primitive: 'integer'},
            extensible: true
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-storagesetcookieparameters
          SetCookieParameters = Serialization::Record.define(
            cookie: {wire_key: 'cookie', ref: 'Storage::PartialCookie'},
            partition: {wire_key: 'partition', required: false, ref: 'Storage::PartitionDescriptor'}
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-storagesetcookieresult
          SetCookieResult = Serialization::Record.define(
            partition_key: {wire_key: 'partitionKey', ref: 'Storage::PartitionKey'}
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-storagedeletecookiesparameters
          DeleteCookiesParameters = Serialization::Record.define(
            filter: {wire_key: 'filter', required: false, ref: 'Storage::CookieFilter'},
            partition: {wire_key: 'partition', required: false, ref: 'Storage::PartitionDescriptor'}
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-storagedeletecookiesresult
          DeleteCookiesResult = Serialization::Record.define(
            partition_key: {wire_key: 'partitionKey', ref: 'Storage::PartitionKey'}
          )

          def cookie_filter(**) = CookieFilter.new(**)
          def browsing_context_partition_descriptor(**) = BrowsingContextPartitionDescriptor.new(**)
          def storage_key_partition_descriptor(**) = StorageKeyPartitionDescriptor.new(**)
          def partition_descriptor = PartitionDescriptor
          def partial_cookie(**) = PartialCookie.new(**)

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#command-storage-deleteCookies
          def delete_cookies(filter: Serialization::UNSET, partition: Serialization::UNSET)
            params = DeleteCookiesParameters.new(filter: filter, partition: partition)
            execute(cmd: 'storage.deleteCookies', params: params, result: Storage::DeleteCookiesResult)
          end

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#command-storage-getCookies
          def get_cookies(filter: Serialization::UNSET, partition: Serialization::UNSET)
            params = GetCookiesParameters.new(filter: filter, partition: partition)
            execute(cmd: 'storage.getCookies', params: params, result: Storage::GetCookiesResult)
          end

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#command-storage-setCookie
          def set_cookie(cookie:, partition: Serialization::UNSET)
            params = SetCookieParameters.new(cookie: cookie, partition: partition)
            execute(cmd: 'storage.setCookie', params: params, result: Storage::SetCookieResult)
          end
        end # Storage
      end # Protocol
    end # BiDi
  end # WebDriver
end # Selenium
