# -*- coding: utf-8 -*- #
# Copyright 2025 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.

"""permissions list command."""


from googlecloudsdk.api_lib.accesscontextmanager import supported_permissions
from googlecloudsdk.calliope import base


@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.GA)
class List(base.ListCommand):
  """Lists all [VPC Service Controls supported permissions].

  Lists the permissions that VPC Service Controls supports.
  """

  _API_VERSION = 'v1'
  detailed_help = {
      'brief': 'Lists all VPC Service Controls supported permissions',
      'DESCRIPTION': (
          'Lists the permissions that VPC Service Controls supports.'
      ),
      'EXAMPLES': (
          """\
  To list VPC Service Controls supported permissions, run:

    $ {command}

  This command prints out a list of all supported permissions in a tabular form:

    PERMISSION
    example.permission.one
  """
      ),
  }

  @staticmethod
  def Args(parser):
    """Args is called by calliope to gather arguments for this command.

    Args:
      parser: An argparse parser that you can use to add arguments that go on
        the command line after this command. Positional arguments are allowed.
    """

    # Remove unneeded list-related flags from parser
    base.URI_FLAG.RemoveFromParser(parser)

    parser.display_info.AddFormat('table(.:label=PERMISSION:sort=1)')

  def Run(self, args):
    """Run 'access-context-manager supported-permissions list'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
        with.

    Returns:
      The list of VPC Service Controls supported permissions.
    """

    client = supported_permissions.Client(version=self._API_VERSION)

    return client.List(args.page_size, args.limit)


@base.ReleaseTracks(base.ReleaseTrack.BETA)
class ListBeta(List):
  _API_VERSION = 'v1'


@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class ListAlpha(List):
  _API_VERSION = 'v1alpha'
