
                             d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddl	mZ dd	lmZ d
 Zej                  fdZej                  fdZd Zd ZefdZy)z#Utilities for handling region flag.    )absolute_import)division)unicode_literals)
exceptions)	constants)log)
properties)
console_ioc                      t         j                  j                  j                  j	                         t         j                  j                  j                  j
                  k(  S N)r	   VALUEScoreuniverse_domainGetdefault     0lib/googlecloudsdk/command_lib/ai/region_util.py_IsDefaultUniverser      sE    ,,002						/	/	7	78r   c                       fdS )z]Returns a no argument function that prompts available regions and catches the user selection.c                      t               S r   )PromptForRegionavailable_regionss   r   <lambda>z(GetPromptForRegionFunc.<locals>.<lambda>%   s    !23r   r   r   s   `r   GetPromptForRegionFuncr   #   s	    	33r   c                     t        j                         rct               rXt        |       }t        j                  |dd      }||   }t
        j                  j                  dj                  |             |S yy)a`  Prompt for region from list of available regions.

  This method is referenced by the declaritive iam commands as a fallthrough
  for getting the region. Prompts only in GDU

  Args:
    available_regions: list of the available regions to choose from

  Returns:
    The region specified by the user, str, or None if not in GDU or cannot
    prompt.
  Please specify a region:
Tmessagecancel_optionGTo make this the default region, run `gcloud config set ai/region {}`.
N)	r
   	CanPromptr   listPromptChoicer   statusPrintformat)r   all_regionsidxregions       r   r   r   (   sr      2 4()K

!
!9OCFJJ ;;A6&>KM !5r   c                     t        j                         rqt               rft        t        j
                        } t        j                  | dd      }| |   }t        j                  j                  dj                  |             |S yy)a&  Prompt for region from list of online prediction available regions.

  This method is referenced by the declaritive iam commands as a fallthrough
  for getting the region. Prompts only in GDU.

  Returns:
    The region specified by the user, str, or None if not in GDU or cannot
    prompt.
  r   Tr   r"   N)r
   r#   r   r$   r   SUPPORTED_OP_REGIONSr%   r   r&   r'   r(   r)   r*   r+   s      r   PromptForOpRegionr/   @   sw      2 4y556K

!
!9OCFJJ ;;A6&>KM !5r   c                     t        j                         rqt               rft        t        j
                        } t        j                  | dd      }| |   }t        j                  j                  dj                  |             |S yy)a-  Prompt for region from list of deployment resource pool available regions.

  This method is referenced by the declaritive iam commands as a fallthrough
  for getting the region. Prompts only in GDU.

  Returns:
    The region specified by the user, str, or None if not in GDU or cannot
    prompt.
  r   Tr   r"   N)r
   r#   r   r$   r   *SUPPORTED_DEPLOYMENT_RESOURCE_POOL_REGIONSr%   r   r&   r'   r(   r.   s      r   .PromptForDeploymentResourcePoolSupportedRegionr2   U   sw      2 4yKKLK

!
!9OCFJJ ;;A6&>KM !5r   c                 >   t        | dd      r| j                  S t        j                  j                  j                  j                         r2t        j                  j                  j                  j                         S  |       }|r|S t        j                  dd      )al  Gets the region and prompt for region if not provided.

    Region is decided in the following order:
  - region argument;
  - ai/region gcloud config;
  - prompt user input (only in GDU).

  Args:
    args: Namespace, The args namespace.
    prompt_func: Function, To prompt for region from list of available regions.

  Returns:
    A str representing region.
  r+   Nz--regionzRegion is required)	getattrr+   r	   r   aiIsExplicitlySetr   r   RequiredArgumentException)argsprompt_funcr+   s      r   	GetRegionr:   j   s~     T8T";;  002&&**,,=&M 	,,Z9MNNr   N)__doc__
__future__r   r   r   googlecloudsdk.callioper   googlecloudsdk.command_lib.air   googlecloudsdk.corer   r	   googlecloudsdk.core.consoler
   r   SUPPORTED_REGIONr   r   r/   r2   r:   r   r   r   <module>rB      s\    * &  ' . 3 # * 2 .7-G-G 4
 '0&@&@ 0** !0 Or   