# 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-session
        class Session < Domain
          # @see https://w3c.github.io/webdriver-bidi/#type-session-UserPromptHandlerType
          USER_PROMPT_HANDLER_TYPE = {
            accept: 'accept',
            dismiss: 'dismiss',
            ignore: 'ignore'
          }.freeze

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#type-session-CapabilitiesRequest
          CapabilitiesRequest = Serialization::Record.define(
            always_match: {wire_key: 'alwaysMatch', required: false, ref: 'Session::CapabilityRequest'},
            first_match: {wire_key: 'firstMatch', required: false, ref: 'Session::CapabilityRequest', list: true}
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#type-session-CapabilityRequest
          CapabilityRequest = Serialization::Record.define(
            accept_insecure_certs: {wire_key: 'acceptInsecureCerts', required: false, primitive: 'boolean'},
            browser_name: {wire_key: 'browserName', required: false, primitive: 'string'},
            browser_version: {wire_key: 'browserVersion', required: false, primitive: 'string'},
            platform_name: {wire_key: 'platformName', required: false, primitive: 'string'},
            proxy: {wire_key: 'proxy', required: false, ref: 'Session::ProxyConfiguration'},
            unhandled_prompt_behavior: {
              wire_key: 'unhandledPromptBehavior',
              required: false,
              ref: 'Session::UserPromptHandler'
            },
            extensible: true
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#type-session-ProxyConfiguration
          class ProxyConfiguration < Serialization::Union
            discriminator 'proxyType', {
              autodetect: 'autodetect',
              direct: 'direct',
              manual: 'manual',
              pac: 'pac',
              system: 'system'
            }
            variants(
              autodetect: 'Session::AutodetectProxyConfiguration',
              direct: 'Session::DirectProxyConfiguration',
              manual: 'Session::ManualProxyConfiguration',
              pac: 'Session::PacProxyConfiguration',
              system: 'Session::SystemProxyConfiguration'
            )
            object_only

            def self.autodetect(**) = Session::AutodetectProxyConfiguration.new(**)
            def self.direct(**) = Session::DirectProxyConfiguration.new(**)
            def self.manual(**) = Session::ManualProxyConfiguration.new(**)
            def self.pac(**) = Session::PacProxyConfiguration.new(**)
            def self.system(**) = Session::SystemProxyConfiguration.new(**)
          end

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-sessionautodetectproxyconfiguration
          AutodetectProxyConfiguration = Serialization::Record.define(
            proxy_type: {wire_key: 'proxyType', fixed: 'autodetect'},
            extensible: true
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-sessiondirectproxyconfiguration
          DirectProxyConfiguration = Serialization::Record.define(
            proxy_type: {wire_key: 'proxyType', fixed: 'direct'},
            extensible: true
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-sessionmanualproxyconfiguration
          ManualProxyConfiguration = Serialization::Record.define(
            proxy_type: {wire_key: 'proxyType', fixed: 'manual'},
            http_proxy: {wire_key: 'httpProxy', required: false, primitive: 'string'},
            ssl_proxy: {wire_key: 'sslProxy', required: false, primitive: 'string'},
            socks_proxy: {wire_key: 'socksProxy', primitive: 'string'},
            socks_version: {wire_key: 'socksVersion', primitive: 'integer'},
            no_proxy: {wire_key: 'noProxy', required: false, list: true},
            extensible: true
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-sessionsocksproxyconfiguration
          SocksProxyConfiguration = Serialization::Record.define(
            socks_proxy: {wire_key: 'socksProxy', primitive: 'string'},
            socks_version: {wire_key: 'socksVersion', primitive: 'integer'}
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-sessionpacproxyconfiguration
          PacProxyConfiguration = Serialization::Record.define(
            proxy_type: {wire_key: 'proxyType', fixed: 'pac'},
            proxy_autoconfig_url: {wire_key: 'proxyAutoconfigUrl', primitive: 'string'},
            extensible: true
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-sessionsystemproxyconfiguration
          SystemProxyConfiguration = Serialization::Record.define(
            proxy_type: {wire_key: 'proxyType', fixed: 'system'},
            extensible: true
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#type-session-UserPromptHandler
          UserPromptHandler = Serialization::Record.define(
            alert: {wire_key: 'alert', required: false, enum: 'Session::USER_PROMPT_HANDLER_TYPE'},
            before_unload: {wire_key: 'beforeUnload', required: false, enum: 'Session::USER_PROMPT_HANDLER_TYPE'},
            confirm: {wire_key: 'confirm', required: false, enum: 'Session::USER_PROMPT_HANDLER_TYPE'},
            default: {wire_key: 'default', required: false, enum: 'Session::USER_PROMPT_HANDLER_TYPE'},
            file: {wire_key: 'file', required: false, enum: 'Session::USER_PROMPT_HANDLER_TYPE'},
            prompt: {wire_key: 'prompt', required: false, enum: 'Session::USER_PROMPT_HANDLER_TYPE'}
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-sessionsubscribeparameters
          SubscribeParameters = Serialization::Record.define(
            events: {wire_key: 'events', list: true},
            contexts: {wire_key: 'contexts', required: false, list: true},
            user_contexts: {wire_key: 'userContexts', required: false, list: true}
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#type-session-UnsubscribeByIDRequest
          UnsubscribeByIDRequest = Serialization::Record.define(subscriptions: {wire_key: 'subscriptions', list: true})

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#type-session-UnsubscribeByAttributesRequest
          UnsubscribeByAttributesRequest = Serialization::Record.define(events: {wire_key: 'events', list: true})

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

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-sessionnewparameters
          NewParameters = Serialization::Record.define(
            capabilities: {wire_key: 'capabilities', ref: 'Session::CapabilitiesRequest'}
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-sessionnewresult
          NewResult = Serialization::Record.define(
            session_id: {wire_key: 'sessionId', primitive: 'string'},
            capabilities: {wire_key: 'capabilities', ref: 'Session::NewResult::Capabilities'}
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          NewResult::Capabilities = Serialization::Record.define(
            accept_insecure_certs: {wire_key: 'acceptInsecureCerts', primitive: 'boolean'},
            browser_name: {wire_key: 'browserName', primitive: 'string'},
            browser_version: {wire_key: 'browserVersion', primitive: 'string'},
            platform_name: {wire_key: 'platformName', primitive: 'string'},
            set_window_rect: {wire_key: 'setWindowRect', primitive: 'boolean'},
            user_agent: {wire_key: 'userAgent', primitive: 'string'},
            proxy: {wire_key: 'proxy', required: false, ref: 'Session::ProxyConfiguration'},
            unhandled_prompt_behavior: {
              wire_key: 'unhandledPromptBehavior',
              required: false,
              ref: 'Session::UserPromptHandler'
            },
            web_socket_url: {wire_key: 'webSocketUrl', 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-sessionsubscriberesult
          SubscribeResult = Serialization::Record.define(subscription: {wire_key: 'subscription', primitive: 'string'})

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-sessionunsubscribeparameters
          class UnsubscribeParameters < Serialization::Union
            presence(
              'Session::UnsubscribeByAttributesRequest' => ['events'],
              'Session::UnsubscribeByIDRequest' => ['subscriptions']
            )
            object_only
          end

          def capabilities_request(**) = CapabilitiesRequest.new(**)
          def capability_request(**) = CapabilityRequest.new(**)
          def proxy_configuration = ProxyConfiguration
          def autodetect_proxy_configuration(**) = AutodetectProxyConfiguration.new(**)
          def direct_proxy_configuration(**) = DirectProxyConfiguration.new(**)
          def manual_proxy_configuration(**) = ManualProxyConfiguration.new(**)
          def pac_proxy_configuration(**) = PacProxyConfiguration.new(**)
          def system_proxy_configuration(**) = SystemProxyConfiguration.new(**)
          def user_prompt_handler(**) = UserPromptHandler.new(**)
          def unsubscribe_by_id_request(**) = UnsubscribeByIDRequest.new(**)
          def unsubscribe_by_attributes_request(**) = UnsubscribeByAttributesRequest.new(**)

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#command-session-end
          def end_
            execute(cmd: 'session.end')
          end

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#command-session-new
          def new(capabilities:)
            params = NewParameters.new(capabilities: capabilities)
            execute(cmd: 'session.new', params: params, result: Session::NewResult)
          end

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#command-session-status
          def status
            execute(cmd: 'session.status', result: Session::StatusResult)
          end

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#command-session-subscribe
          def subscribe(events:, contexts: Serialization::UNSET, user_contexts: Serialization::UNSET)
            params = SubscribeParameters.new(events: events, contexts: contexts, user_contexts: user_contexts)
            execute(cmd: 'session.subscribe', params: params, result: Session::SubscribeResult)
          end

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#command-session-unsubscribe
          def unsubscribe(events: Serialization::UNSET, subscriptions: Serialization::UNSET)
            params = UnsubscribeParameters.build(events: events, subscriptions: subscriptions)
            execute(cmd: 'session.unsubscribe', params: params)
          end
        end # Session
      end # Protocol
    end # BiDi
  end # WebDriver
end # Selenium
