# 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.

# This file is automatically generated. DO NOT EDIT!
# 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/
        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/
          ClientWindowInfo = Serialization::Record.define(
            active: {wire_key: 'active', primitive: 'boolean'},
            client_window: 'clientWindow',
            height: 'height',
            state: {wire_key: 'state', enum: 'Browser::CLIENT_WINDOW_INFO_STATE'},
            width: 'width',
            x: 'x',
            y: 'y'
          )

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          UserContextInfo = Serialization::Record.define(user_context: 'userContext')

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          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/
          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/
          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/
          RemoveUserContextParameters = Serialization::Record.define(user_context: 'userContext')

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

            # @api private
            # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
            ClientWindowNamedState = Serialization::Record.define(
              client_window: 'clientWindow',
              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: 'clientWindow',
              width: {wire_key: 'width', required: false},
              height: {wire_key: 'height', required: false},
              x: {wire_key: 'x', required: false},
              y: {wire_key: 'y', required: false}
            )
          end

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          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/
          class DownloadBehavior < Serialization::Union
            discriminator 'type', {allowed: 'allowed', denied: 'denied'}
            variants(
              allowed: 'Browser::DownloadBehavior::Allowed',
              denied: 'Browser::DownloadBehavior::Denied'
            )

            # @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'})
          end

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

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          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/
          def get_client_windows
            execute(cmd: 'browser.getClientWindows', result: Browser::GetClientWindowsResult)
          end

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

          # @api private
          # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/
          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/
          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/
          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
