# coding: utf-8
# Copyright (c) 2016, 2026, Oracle and/or its affiliates.  All rights reserved.
# This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
# NOTE: This class is auto generated by OracleSDKGenerator. DO NOT EDIT. API Version: 20180828

from __future__ import print_function
import click
import oci  # noqa: F401
import six  # noqa: F401
import sys  # noqa: F401
from oci_cli import cli_constants  # noqa: F401
from oci_cli import cli_util
from oci_cli import json_skeleton_utils
from oci_cli import custom_types  # noqa: F401
from oci_cli.aliasing import CommandGroupWithAlias
from services.multicloud.src.oci_cli_multicloud.generated import multicloud_service_cli


@click.command(cli_util.override('multicloud_resources.multicloud_resources_root_group.command_name', 'multicloud-resources'), cls=CommandGroupWithAlias, help=cli_util.override('multicloud_resources.multicloud_resources_root_group.help', """Use the Oracle Multicloud API to retrieve resource anchors and network anchors, and the metadata mappings related a Cloud Service Provider. For more information, see [Oracle Multicloud Hub]."""), short_help=cli_util.override('multicloud_resources.multicloud_resources_root_group.short_help', """Oracle Multicloud API"""))
@cli_util.help_option_group
def multicloud_resources_root_group():
    pass


@click.command(cli_util.override('multicloud_resources.multicloud_resource_collection_group.command_name', 'multicloud-resource-collection'), cls=CommandGroupWithAlias, help="""Multicloud resources in the indicated Multicloud subscription. For more information, see [Multicloud Resources].""")
@cli_util.help_option_group
def multicloud_resource_collection_group():
    pass


multicloud_service_cli.multicloud_service_group.add_command(multicloud_resources_root_group)
multicloud_resources_root_group.add_command(multicloud_resource_collection_group)


@multicloud_resource_collection_group.command(name=cli_util.override('multicloud_resources.list_multicloud_resources.command_name', 'list-multicloud-resources'), help=u"""Lists Multicloud resources in the specified Multicloud subscription. Details for each resource include Multicloud base compartment, name, state, resource type, and network anchor. For more information, see [Multicloud Resources]. \n[Command Reference](listMulticloudResources)""")
@cli_util.option('--resource-anchor-id', help=u"""The [OCID] of the resource anchor.""")
@cli_util.option('--compartment-id', help=u"""The [OCID] of the compartment in which to list resources.""")
@cli_util.option('--limit', type=click.INT, help=u"""For list pagination. The maximum number of results per page, or items to return in a paginated \"List\" call. For important details about how pagination works, see [List Pagination].""")
@cli_util.option('--page', help=u"""For list pagination. The value of the opc-next-page response header from the previous \"List\" call. For important details about how pagination works, see [List Pagination].""")
@cli_util.option('--sort-order', type=custom_types.CliCaseInsensitiveChoice(["ASC", "DESC"]), help=u"""The sort order to use, either ascending (`ASC`) or descending (`DESC`). In general, the sort order is `DESC` when sorting by time and `ASC` otherwise.""")
@cli_util.option('--sort-by', type=custom_types.CliCaseInsensitiveChoice(["timeCreated", "displayName"]), help=u"""The field to sort by. You can provide only one sort order. Default order for `timeCreated` is descending. Default order for `displayName` is ascending.""")
@cli_util.option('--subscription-service-name', type=custom_types.CliCaseInsensitiveChoice(["ORACLEDBATAZURE", "ORACLEDBATGOOGLE", "ORACLEDBATAWS"]), help=u"""The cloud service provider.""")
@cli_util.option('--subscription-id', help=u"""The [OCID] of the Multicloud subscription in which to list resources.""")
@cli_util.option('--external-location', help=u"""The cloud service provider region.""")
@cli_util.option('--resource-type', help=u"""Filter alerts by resource type (e.g. ADBD, VMCluster).""")
@cli_util.option('--all', 'all_pages', is_flag=True, help="""Fetches all pages of results. If you provide this option, then you cannot provide the --limit option.""")
@cli_util.option('--page-size', type=click.INT, help="""When fetching results, the number of results to fetch per call. Only valid when used with --all or --limit, and ignored otherwise.""")
@json_skeleton_utils.get_cli_json_input_option({})
@cli_util.help_option
@click.pass_context
@json_skeleton_utils.json_skeleton_generation_handler(input_params_to_complex_types={}, output_type={'module': 'multicloud', 'class': 'MulticloudResourceCollection'})
@cli_util.wrap_exceptions
def list_multicloud_resources(ctx, from_json, all_pages, page_size, resource_anchor_id, compartment_id, limit, page, sort_order, sort_by, subscription_service_name, subscription_id, external_location, resource_type):

    if all_pages and limit:
        raise click.UsageError('If you provide the --all option you cannot provide the --limit option')

    kwargs = {}
    if resource_anchor_id is not None:
        kwargs['resource_anchor_id'] = resource_anchor_id
    if compartment_id is not None:
        kwargs['compartment_id'] = compartment_id
    if limit is not None:
        kwargs['limit'] = limit
    if page is not None:
        kwargs['page'] = page
    if sort_order is not None:
        kwargs['sort_order'] = sort_order
    if sort_by is not None:
        kwargs['sort_by'] = sort_by
    if subscription_service_name is not None:
        kwargs['subscription_service_name'] = subscription_service_name
    if subscription_id is not None:
        kwargs['subscription_id'] = subscription_id
    if external_location is not None:
        kwargs['external_location'] = external_location
    if resource_type is not None:
        kwargs['resource_type'] = resource_type
    kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(ctx.obj['request_id'])
    client = cli_util.build_client('multicloud', 'multicloud_resources', ctx)
    if all_pages:
        if page_size:
            kwargs['limit'] = page_size

        result = cli_util.list_call_get_all_results(
            client.list_multicloud_resources,
            **kwargs
        )
    elif limit is not None:
        result = cli_util.list_call_get_up_to_limit(
            client.list_multicloud_resources,
            limit,
            page_size,
            **kwargs
        )
    else:
        result = client.list_multicloud_resources(
            **kwargs
        )
    cli_util.render_response(result, ctx)
