- release_tracks: [ALPHA, BETA, GA]
  command_type: GENERIC

  help_text:
    brief: |
      Replace all existing access levels.
    description: |
      Replace all existing access level in specified access policy with access levels specified in a
      file.

      ## EXAMPLES

      To replace all levels within a policy, using etag:

        $ {command} my-policy-number --source-file=path-to-file-containing-all-replacement-access-levels.yaml --etag=optional-latest-etag-of-policy

      To replace all levels within a policy, without using etag:

        $ {command} my-policy-number --source-file=path-to-file-containing-all-replacement-access-levels.yaml

  request:
    collection: accesscontextmanager.accessPolicies.accessLevels
    ALPHA:
      api_version: v1alpha
      method: replaceAll
    BETA:
      api_version: v1
      method: replaceAll
    GA:
      api_version: v1
      method: replaceAll
  response:
    ALPHA:
      modify_response_hooks:
      - googlecloudsdk.command_lib.accesscontextmanager.levels:ParseReplaceAccessLevelsResponse:api_version=v1alpha
    BETA:
      modify_response_hooks:
      - googlecloudsdk.command_lib.accesscontextmanager.levels:ParseReplaceAccessLevelsResponse:api_version=v1
    GA:
      modify_response_hooks:
      - googlecloudsdk.command_lib.accesscontextmanager.levels:ParseReplaceAccessLevelsResponse:api_version=v1

  arguments:
    resource:
      help_text: The access policy that contains the levels you want to replace.
      spec: !REF googlecloudsdk.command_lib.accesscontextmanager.resources:policy
      override_resource_collection: true

    params:
    - api_field: replaceAccessLevelsRequest.etag
      arg_name: etag
      required: false
      help_text: |
        An etag which specifies the version of the Access Policy. Only etags
        that represent the latest version of the Access Policy will be accepted.
      repeated: false
    - api_field: replaceAccessLevelsRequest.accessLevels
      arg_name: source-file
      required: true
      help_text: |
        Path to a file containing a list of access levels.

        An access level file is a YAML-formatted list of access levels,
        which are YAML objects representing a Basic or Custom level as described in
        the API reference. For example:

        ```
        - name: accessPolicies/my_policy/accessLevels/my_level
          title: My Basic Level
          description: Basic level for foo.
          basic:
            combiningFunction: AND
            conditions:
            - ipSubnetworks:
              - 192.168.100.14/24
              - 2001:db8::/48
            - members
              - user1:user1@example.com
        - name: accessPolicies/my_policy/accessLevels/my_other_level
          title: My Other Custom Level
          description: Custom level for bar.
          custom:
            expr:
              expression: "origin.region_code in ['US', 'CA']"
        ```

        For more information about the alpha version, see:
        https://cloud.google.com/access-context-manager/docs/reference/rest/v1alpha/accessPolicies.accessLevels
        For other versions, see:
        https://cloud.google.com/access-context-manager/docs/reference/rest/v1/accessPolicies.accessLevels
      repeated: false
      ALPHA:
        processor: googlecloudsdk.command_lib.accesscontextmanager.levels:ParseAccessLevels:api_version=v1alpha
      BETA:
        processor: googlecloudsdk.command_lib.accesscontextmanager.levels:ParseAccessLevels:api_version=v1
      GA:
        processor: googlecloudsdk.command_lib.accesscontextmanager.levels:ParseAccessLevels:api_version=v1
