# 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: Create a new group.
    description: Create a new group.
    GA:
      examples: |
        To quickly create a new Google Groups discussion group with default settings:

          $ {command} eng-discuss@example.com --organization="example.com"

        To create a new Google Groups discussion group with a display name and descripton:

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

        To create a new security group:

          $ {command} security-group@example.com  \
              --organization="example.com"  \
              --group-type="security" \
              --display-name="Security Group"  \
              --description="Description of Security Group"
    BETA:
      examples: |
        To quickly create a new Google Groups discussion group with default settings:

          $ {command} eng-discuss@example.com --organization="example.com"

        To create a new Google Groups discussion group with a display name and descripton:

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

        To create a new security group:

          $ {command} security-group@example.com  \
              --organization="example.com"  \
              --group-type="security" \
              --display-name="Security Group"  \
              --description="Description of Security Group"

    ALPHA:
      examples: |
        To quickly create a new Google Groups discussion group with default settings:

          $ {command} eng-discuss@example.com --organization="example.com"

        To create a new Google Groups discussion group with a display name and descripton:

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

        To create a new security group:

          $ {command} security-group@example.com  \
              --organization="example.com"  \
              --group-type="security" \
              --display-name="Security Group"  \
              --description="Description of Security Group"

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

    - group:
        mutex: true
        required: true
        params:
        - arg_name: organization
          type: str
          help_text: |
            The organization the Group being created belongs to. This can be
            specified either as an ID ("123456789") or as the associated domain
            ("example.com").

        - arg_name: customer
          release_tracks: [GA]
          type: str
          help_text: |
            The customer ID for the customer\'s G Suite account.
            Example of customer: "C01k1e9nw"


    - arg_name: with-initial-owner
      api_field: initialGroupConfig
      help_text: |
        If specified the user making the request will be added as the initial owner of the group being
        created.
      choices:
      - arg_value: with-initial-owner
        enum_value: with-initial-owner
        help_text: |
          The creator of the group will be the owner of the group. This is
          the default for non-dynamic groups.
      - arg_value: empty
        enum_value: empty
        help_text: |
          The creator of the group will not be the owner of the group. This is
          the default for dynamic groups.

    - arg_name: display-name
      api_field: group.displayName
      help_text: |
        The Group's display name.

    - arg_name: description
      api_field: group.description
      help_text: |
        An extended description to help users determine the purpose of a Group. For
        example, you can include information about who should join the Group, the
        types of messages to send to the Group, links to FAQs about the Group, or
        related Groups. Maximum length is 4,096 characters.

    - arg_name: dynamic-user-query
      release_tracks: [ALPHA, BETA, GA]
      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')"

    - group:
        mutex: true
        params:
        - arg_name: labels
          type: str
          help_text: |
            Labels for group resource.
            Example of labels "--labels cloudidentity.googleapis.com/groups.discussion_forum"
        - arg_name: group-type
          help_text: |
            The type of group to create. Setting group-type will add the
            appropriate labels for the type of group being created.
          choices:
          - arg_value: discussion
            enum_value: discussion
            help_text: Creates a Google Groups discussion group.
          - arg_value: dynamic
            enum_value: dynamic
            help_text: Creates a dynamic group.
          - arg_value: security
            enum_value: security
            help_text: Creates a security group.
          default: discussion

    - arg_name: posix-group
      release_tracks: [ALPHA, BETA]
      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 name of the POSIX group that you want to associate
        with the specified Cloud Identity group. You can specify multiple POSIX
        groups with multiple instances of this flag.

        For example, use '--posix-group=gid=1005,name=eng' to add a single
        group, or '--posix-group=gid=1005,name=eng
        --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).

  request:
    collection: cloudidentity.groups
    disable_resource_check: true
    method: create
    ALPHA:
      api_version: v1alpha1
      modify_request_hooks:
      - googlecloudsdk.command_lib.identity.groups.hooks:SetParent
      - googlecloudsdk.command_lib.identity.groups.hooks:SetEntityKey
      - googlecloudsdk.command_lib.identity.groups.hooks:SetLabelsCreate
      - googlecloudsdk.command_lib.identity.groups.hooks:SetDynamicUserQuery
      - googlecloudsdk.command_lib.identity.groups.hooks:SetInitialOwner
    BETA:
      api_version: v1beta1
      modify_request_hooks:
      - googlecloudsdk.command_lib.identity.groups.hooks:SetParent
      - googlecloudsdk.command_lib.identity.groups.hooks:SetEntityKey
      - googlecloudsdk.command_lib.identity.groups.hooks:SetLabelsCreate
      - googlecloudsdk.command_lib.identity.groups.hooks:SetDynamicUserQuery
      - googlecloudsdk.command_lib.identity.groups.hooks:SetInitialOwner
    GA:
      api_version: v1
      modify_request_hooks:
      - googlecloudsdk.command_lib.identity.groups.hooks:SetParent
      - googlecloudsdk.command_lib.identity.groups.hooks:SetEntityKey
      - googlecloudsdk.command_lib.identity.groups.hooks:SetLabelsCreate
      - googlecloudsdk.command_lib.identity.groups.hooks:SetDynamicUserQuery
      - googlecloudsdk.command_lib.identity.groups.hooks:SetInitialOwner

  response:
    result_attribute: response
