# 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-browser
        class Browser < Domain
          CLIENT_WINDOW_INFO_STATE = {
            fullscreen: 'fullscreen',
            maximized: 'maximized',
            minimized: 'minimized',
            normal: 'normal'
          }.freeze

          CLIENT_WINDOW_NAMED_STATE_STATE = {
            fullscreen: 'fullscreen',
            maximized: 'maximized',
            minimized: 'minimized'
          }.freeze

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#type-browser-ClientWindowInfo
          ClientWindowInfo = Serialization::Record.define(
            active: {wire_key: 'active', primitive: 'boolean'},
            client_window: {wire_key: 'clientWindow', primitive: 'string'},
            height: {wire_key: 'height', primitive: 'integer'},
            state: {wire_key: 'state', enum: 'Browser::CLIENT_WINDOW_INFO_STATE'},
            width: {wire_key: 'width', primitive: 'integer'},
            x: {wire_key: 'x', primitive: 'integer'},
            y: {wire_key: 'y', primitive: 'integer'}
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#type-browser-UserContextInfo
          UserContextInfo = Serialization::Record.define(user_context: {wire_key: 'userContext', primitive: 'string'})

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-browsercreateusercontextparameters
          CreateUserContextParameters = Serialization::Record.define(
            accept_insecure_certs: {wire_key: 'acceptInsecureCerts', required: false, primitive: 'boolean'},
            proxy: {wire_key: 'proxy', required: false, ref: 'Session::ProxyConfiguration'},
            unhandled_prompt_behavior: {
              wire_key: 'unhandledPromptBehavior',
              required: false,
              ref: 'Session::UserPromptHandler'
            }
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-browsergetclientwindowsresult
          GetClientWindowsResult = Serialization::Record.define(
            client_windows: {wire_key: 'clientWindows', ref: 'Browser::ClientWindowInfo', list: true}
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-browsergetusercontextsresult
          GetUserContextsResult = Serialization::Record.define(
            user_contexts: {wire_key: 'userContexts', ref: 'Browser::UserContextInfo', list: true}
          )

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

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-browsersetclientwindowstateparameters
          class SetClientWindowStateParameters < Serialization::Union
            discriminator 'state', {normal: 'normal'}
            variants(
              normal: 'Browser::SetClientWindowStateParameters::ClientWindowRectState'
            )
            fallback 'Browser::SetClientWindowStateParameters::ClientWindowNamedState'
            object_only

            # @api private
            # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
            ClientWindowNamedState = Serialization::Record.define(
              client_window: {wire_key: 'clientWindow', primitive: 'string'},
              state: {wire_key: 'state', enum: 'Browser::CLIENT_WINDOW_NAMED_STATE_STATE'}
            )

            # @api private
            # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
            ClientWindowRectState = Serialization::Record.define(
              state: {fixed: 'normal'},
              client_window: {wire_key: 'clientWindow', primitive: 'string'},
              width: {wire_key: 'width', required: false, primitive: 'integer'},
              height: {wire_key: 'height', required: false, primitive: 'integer'},
              x: {wire_key: 'x', required: false, primitive: 'integer'},
              y: {wire_key: 'y', required: false, primitive: 'integer'}
            )

            def self.normal(**) = Browser::SetClientWindowStateParameters::ClientWindowRectState.new(**)
          end

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#cddl-type-browsersetdownloadbehaviorparameters
          SetDownloadBehaviorParameters = Serialization::Record.define(
            download_behavior: {wire_key: 'downloadBehavior', nullable: true, ref: 'Browser::DownloadBehavior'},
            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/#cddl-type-browserdownloadbehavior
          class DownloadBehavior < Serialization::Union
            discriminator 'type', {allowed: 'allowed', denied: 'denied'}
            variants(
              allowed: 'Browser::DownloadBehavior::Allowed',
              denied: 'Browser::DownloadBehavior::Denied'
            )
            object_only

            # @api private
            # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
            Allowed = Serialization::Record.define(
              type: {fixed: 'allowed'},
              destination_folder: {wire_key: 'destinationFolder', primitive: 'string'}
            )

            # @api private
            # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
            Denied = Serialization::Record.define(type: {fixed: 'denied'})

            def self.allowed(**) = Browser::DownloadBehavior::Allowed.new(**)
            def self.denied(**) = Browser::DownloadBehavior::Denied.new(**)
          end

          def download_behavior = DownloadBehavior

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

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#command-browser-createUserContext
          def create_user_context(
            accept_insecure_certs: Serialization::UNSET,
            proxy: Serialization::UNSET,
            unhandled_prompt_behavior: Serialization::UNSET
          )
            params = CreateUserContextParameters.new(
              accept_insecure_certs: accept_insecure_certs,
              proxy: proxy,
              unhandled_prompt_behavior: unhandled_prompt_behavior
            )
            execute(cmd: 'browser.createUserContext', params: params, result: Browser::UserContextInfo)
          end

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#command-browser-getClientWindows
          def get_client_windows
            execute(cmd: 'browser.getClientWindows', result: Browser::GetClientWindowsResult)
          end

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#command-browser-getUserContexts
          def get_user_contexts
            execute(cmd: 'browser.getUserContexts', result: Browser::GetUserContextsResult)
          end

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#command-browser-removeUserContext
          def remove_user_context(user_context:)
            params = RemoveUserContextParameters.new(user_context: user_context)
            execute(cmd: 'browser.removeUserContext', params: params)
          end

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#command-browser-setClientWindowState
          def set_client_window_state(
            client_window:,
            state:,
            width: Serialization::UNSET,
            height: Serialization::UNSET,
            x: Serialization::UNSET,
            y: Serialization::UNSET
          )
            Serialization.validate!(
              'state',
              state,
              {normal: 'normal', fullscreen: 'fullscreen', maximized: 'maximized', minimized: 'minimized'}
            )
            params = SetClientWindowStateParameters.build(
              client_window: client_window,
              state: state,
              width: width,
              height: height,
              x: x,
              y: y
            )
            execute(cmd: 'browser.setClientWindowState', params: params, result: Browser::ClientWindowInfo)
          end

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          # @see https://w3c.github.io/webdriver-bidi/#command-browser-setDownloadBehavior
          def set_download_behavior(download_behavior:, user_contexts: Serialization::UNSET)
            params = SetDownloadBehaviorParameters.new(
              download_behavior: download_behavior,
              user_contexts: user_contexts
            )
            execute(cmd: 'browser.setDownloadBehavior', params: params)
          end
        end # Browser
      end # Protocol
    end # BiDi
  end # WebDriver
end # Selenium
