# Copyright 2020 Google LLC. All Rights Reserved.
#
# Licensed 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.
- release_tracks: [ALPHA, BETA, GA]

  help_text:
    brief: Update a group.
    description: Update a group.
    GA:
      examples: |
        To update a group:

          $ {command} eng-discuss@foo.com  \
              --display-name="New Engineer Discuss"  \
              --description="Group for engineering discussions"
    BETA:
      examples: |
        To update a group:

          $ {command} eng-discuss@foo.com  \
              --display-name="New Engineer Discuss"  \
              --description="Group for engineering discussions"

        To remove POSIX information from a Google Group:

          $ {command} eng-discuss@foo.com \
              --remove-posix-groups=eng
    ALPHA:
      examples: |
        To update a group:

          $ {command} eng-discuss@foo.com  \
              --display-name="New Engineer Discuss"  \
              --description="Group for engineering discussions"

        To remove POSIX information from a Google Group:

          $ {command} eng-discuss@foo.com \
              --remove-posix-groups=eng

  arguments:
    params:
    - arg_name: email
      is_positional: true
      required: true
      help_text: |
        The email address of the group to be updated.

    - group:
        mutex: true
        params:
        - arg_name: display-name
          api_field: group.displayName
          help_text: |
            Replace existing display name on group being updated.
        - arg_name: clear-display-name
          type: bool
          help_text: |
            Clear existing display name on group being updated.

    - group:
        mutex: true
        params:
        - arg_name: description
          api_field: group.description
          help_text: Replace existing description on group being updated.
        - arg_name: clear-description
          type: bool
          help_text: Clear existing description on group being updated.

    - group:
        release_tracks: [ALPHA, BETA]
        mutex: true
        params:
        - arg_name: add-posix-group
          api_field: group.posixGroups
          hidden: true
          type:
            arg_dict:
              flatten: false
              spec:
              - api_field: gid
                arg_name: gid
                type: int
              - api_field: name
                arg_name: name
                type: str
          help_text: |
            Group id (gid) and a name for a POSIX group that you want to add
            to the specified Cloud Identity group. You can specify multiple
            POSIX groups to add with multiple instances of this flag.

            For example, use '--add-posix-group=gid=1005,name=eng'
            to add a single group, or '--add-posix-group=gid=1005,name=eng
            --add-posix-group=gid=1006,name=docs' to add multiple groups.

            Caution: POSIX groups are deprecated. As of September 26, 2024, you
            can no longer create new POSIX groups. For more information, see
            [POSIX groups
            deprecation](https://cloud.google.com/identity/docs/deprecations/posix-groups).

        - arg_name: remove-posix-groups
          type: "googlecloudsdk.calliope.arg_parsers:ArgList:"
          metavar: POSIX_GROUP
          help_text: |
            Remove POSIX groups from the specified Cloud Identity group.
            You can specify multiple POSIX groups by either name or gid by
            using a comma-separated list.

            For example, use '--remove-posix-groups=1005,1006' to remove POSIX
            groups with group ids '1005' and '1006', or use
            '--remove-posix-groups=eng,docs' to remove POSIX groups named 'eng'
            and 'docs'.
        - arg_name: clear-posix-groups
          type: bool
          help_text: |
            Clear all POSIX groups from the specified Cloud Identity
            group.

    - arg_name: labels
      release_tracks: [BETA, GA]
      ALPHA:
        hidden: true
      type: str
      help_text: |
        One or more label entries that apply to the group. Currently supported labels contain a key
        with an empty value.

        Google Groups are the default type of group and have a label with a key of
        'cloudidentity.googleapis.com/groups.discussion_forum' and an empty value.

        Existing Google Groups can have an additional label with a key of
        'cloudidentity.googleapis.com/groups.security' and an empty value added to them.
        *This is an immutable change and the security label cannot be removed once added.*

        Dynamic groups have a label with a key of 'cloudidentity.googleapis.com/groups.dynamic'.

        Identity-mapped groups for Cloud Search have a label with a key of 'system/groups/external'
        and an empty value.

        Examples: {"cloudidentity.googleapis.com/groups.discussion_forum": ""} or
        {"system/groups/external": ""}.

    - arg_name: dynamic-user-query
      type: str
      help_text: |
        Query that determines the memberships of the dynamic group.

        Example of a query:
        `--dynamic-user-query="user.organizations.exists(org,org.title=='SWE')"`

  request:
    collection: cloudidentity.groups
    disable_resource_check: true
    method: patch
    ALPHA:
      api_version: v1alpha1
      modify_request_hooks:
      - googlecloudsdk.command_lib.identity.groups.hooks:SetResourceName
      - googlecloudsdk.command_lib.identity.groups.hooks:SetGroupUpdateMask
      - googlecloudsdk.command_lib.identity.groups.hooks:UpdatePosixGroups
      - googlecloudsdk.command_lib.identity.groups.hooks:SetDynamicUserQuery
    BETA:
      api_version: v1beta1
      modify_request_hooks:
      - googlecloudsdk.command_lib.identity.groups.hooks:SetResourceName
      - googlecloudsdk.command_lib.identity.groups.hooks:SetGroupUpdateMask
      - googlecloudsdk.command_lib.identity.groups.hooks:SetLabels
      - googlecloudsdk.command_lib.identity.groups.hooks:UpdatePosixGroups
      - googlecloudsdk.command_lib.identity.groups.hooks:SetDynamicUserQuery
    GA:
      api_version: v1
      modify_request_hooks:
      - googlecloudsdk.command_lib.identity.groups.hooks:SetResourceName
      - googlecloudsdk.command_lib.identity.groups.hooks:SetGroupUpdateMask
      - googlecloudsdk.command_lib.identity.groups.hooks:SetLabels
      - googlecloudsdk.command_lib.identity.groups.hooks:SetDynamicUserQuery

  response:
    result_attribute: response
