text: #!/usr/bin/python
  #
  # Copyright (c) 2019 Zim Kalinowski, (@zikalino)
  #
  # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
  
  from __future__ import absolute_import, division, print_function
  __metaclass__ = type
  
  
  ANSIBLE_METADATA = {'metadata_version': '1.1',
                      'status': ['preview'],
                      'supported_by': 'community'}
  
  
  DOCUMENTATION = '''
  ---
  module: apimanagementemailtemplate_info
  version_added: '2.9'
  short_description: Get EmailTemplate info.
  description:
    - Get info of EmailTemplate.
  options:
    resource_group:
      description:
        - The name of the resource group.
      required: true
      type: str
    service_name:
      description:
        - The name of the API Management service.
      required: true
      type: str
    name:
      description:
        - Resource name.
      type: str
    id:
      description:
        - Resource ID.
      type: str
    type:
      description:
        - Resource type for API Management resource.
      type: str
    subject:
      description:
        - Subject of the Template.
      required: true
      type: str
    body:
      description:
        - Email Template Body. This should be a valid XDocument
      required: true
      type: str
    title:
      description:
        - Title of the Template.
      type: str
    description:
      description:
        - Description of the Email Template.
      type: str
    is_default:
      description:
        - >-
          Whether the template is the default template provided by Api Management
          or has been edited.
      type: boolean
    parameters:
      description:
        - Email Template Parameter values.
      type: list
      suboptions:
        name:
          description:
            - Template parameter name.
          type: str
        title:
          description:
            - Template parameter title.
          type: str
        description:
          description:
            - Template parameter description.
          type: str
  extends_documentation_fragment:
    - azure
  author:
    - Zim Kalinowski (@zikalino)
  
  '''
  
  EXAMPLES = '''
  - name: ApiManagementListEmailTemplates
    azure.rm.apimanagementemailtemplate.info:
      resource_group: myResourceGroup
      service_name: myService
  - name: ApiManagementGetEmailTemplate
    azure.rm.apimanagementemailtemplate.info:
      resource_group: myResourceGroup
      service_name: myService
      name: myTemplate
  
  '''
  
  RETURN = '''
  email_template:
    description: >-
      A list of dict results where the key is the name of the EmailTemplate and
      the values are the facts for that EmailTemplate.
    returned: always
    type: complex
    contains:
      emailtemplate_name:
        description: The key is the name of the server that the values relate to.
        type: complex
        contains:
          id:
            description:
              - Resource ID.
            returned: always
            type: str
            sample: null
          name:
            description:
              - Resource name.
            returned: always
            type: str
            sample: null
          type:
            description:
              - Resource type for API Management resource.
            returned: always
            type: str
            sample: null
          properties:
            description:
              - Email Template entity contract properties.
            returned: always
            type: dict
            sample: null
  
  '''
  
  import time
  import json
  from ansible.module_utils.azure_rm_common import AzureRMModuleBase
  from ansible.module_utils.azure_rm_common_rest import GenericRestClient
  from copy import deepcopy
  from msrestazure.azure_exceptions import CloudError
  
  
  class AzureRMEmailTemplateInfo(AzureRMModuleBase):
      def __init__(self):
          self.module_arg_spec = dict(
              resource_group=dict(
                  type='str',
                  required=true
              ),
              service_name=dict(
                  type='str',
                  required=true
              ),
              name=dict(
                  type='str'
              )
          )
  
          self.resource_group = None
          self.service_name = None
          self.name = None
          self.id = None
          self.name = None
          self.type = None
          self.properties = None
  
          self.results = dict(changed=False)
          self.mgmt_client = None
          self.state = None
          self.url = None
          self.status_code = [200]
  
          self.query_parameters = {}
          self.query_parameters['api-version'] = '2019-01-01'
          self.header_parameters = {}
          self.header_parameters['Content-Type'] = 'application/json; charset=utf-8'
  
          self.mgmt_client = None
          super(AzureRMEmailTemplateInfo, self).__init__(self.module_arg_spec, supports_tags=True)
  
      def exec_module(self, **kwargs):
  
          for key in self.module_arg_spec:
              setattr(self, key, kwargs[key])
  
          self.mgmt_client = self.get_mgmt_svc_client(GenericRestClient,
                                                      base_url=self._cloud_environment.endpoints.resource_manager)
  
          if (self.resource_group is not None and
              self.service_name is not None and
              self.name is not None):
              self.results['email_template'] = self.format_item(self.get())
          elif (self.resource_group is not None and
                self.service_name is not None):
              self.results['email_template'] = self.format_item(self.listbyservice())
          return self.results
  
      def get(self):
          response = None
          results = {}
          # prepare url
          self.url = ('/subscriptions' +
                      '/{{ subscription_id }}' +
                      '/resourceGroups' +
                      '/{{ resource_group }}' +
                      '/providers' +
                      '/Microsoft.ApiManagement' +
                      '/service' +
                      '/{{ service_name }}' +
                      '/templates' +
                      '/{{ template_name }}')
          self.url = self.url.replace('{{ subscription_id }}', self.subscription_id)
          self.url = self.url.replace('{{ resource_group }}', self.resource_group)
          self.url = self.url.replace('{{ service_name }}', self.service_name)
          self.url = self.url.replace('{{ template_name }}', self.name)
  
          try:
              response = self.mgmt_client.query(self.url,
                                                'GET',
                                                self.query_parameters,
                                                self.header_parameters,
                                                None,
                                                self.status_code,
                                                600,
                                                30)
              results['temp_item'] = json.loads(response.text)
              # self.log('Response : {0}'.format(response))
          except CloudError as e:
              self.log('Could not get info for @(Model.ModuleOperationNameUpper).')
  
          return results
  
      def listbyservice(self):
          response = None
          results = {}
          # prepare url
          self.url = ('/subscriptions' +
                      '/{{ subscription_id }}' +
                      '/resourceGroups' +
                      '/{{ resource_group }}' +
                      '/providers' +
                      '/Microsoft.ApiManagement' +
                      '/service' +
                      '/{{ service_name }}' +
                      '/templates')
          self.url = self.url.replace('{{ subscription_id }}', self.subscription_id)
          self.url = self.url.replace('{{ resource_group }}', self.resource_group)
          self.url = self.url.replace('{{ service_name }}', self.service_name)
          self.url = self.url.replace('{{ template_name }}', self.name)
  
          try:
              response = self.mgmt_client.query(self.url,
                                                'GET',
                                                self.query_parameters,
                                                self.header_parameters,
                                                None,
                                                self.status_code,
                                                600,
                                                30)
              results['temp_item'] = json.loads(response.text)
              # self.log('Response : {0}'.format(response))
          except CloudError as e:
              self.log('Could not get info for @(Model.ModuleOperationNameUpper).')
  
          return results
  
      def format_item(item):
          return item
  
  
  def main():
      AzureRMEmailTemplateInfo()
  
  
  if __name__ == '__main__':
      main()
  