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

"""'logging recent_queries list' command."""

import argparse

from googlecloudsdk.api_lib.logging import util
from googlecloudsdk.calliope import base
from googlecloudsdk.generated_clients.apis.logging.v2 import logging_v2_messages as messages

DETAILED_HELP = {
    'DESCRIPTION': (
        """\
        List recent queries for a parent resource (project, billing account, folder, or organization).
    """
    ),
    'EXAMPLES': (
        """\
        To list recent queries in a project, run:

          $ {command} --project=my-project --location=global
    """
    ),
}


@base.Hidden
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.GA)
class List(base.ListCommand):
  """List Logging recent queries.

  Lists recent queries in Google Cloud Logging.
  """

  @staticmethod
  def Args(parser: argparse.ArgumentParser) -> None:
    """Registers flags for this command.

    Args:
      parser: An argparse.ArgumentParser object. The parser that will be used to
        parse the command line arguments.
    """
    util.AddParentArgs(parser, 'parent resource for recent queries to list')
    util.AddBucketLocationArg(
        parser, True, 'Location of the recent queries to list.'
    )

  def Run(self, args: argparse.Namespace) -> messages.ListRecentQueriesResponse:
    """This is what gets called when the user runs this command.

    Lists recent queries using the Logging API.

    Args:
      args: An argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      A ListRecentQueriesResponse message.
    """

    client = util.GetClient()
    return client.projects_locations_recentQueries.List(
        messages.LoggingProjectsLocationsRecentQueriesListRequest(
            parent=f'{util.GetParentFromArgs(args)}/locations/{args.location}',
        )
    )


List.detailed_help = DETAILED_HELP
