"""
Send Templated Email
Send templated transactional email to one recipient.
"""

name = "communication/send-templated-email"
version = "1.0.1"

"""
Send Templated Email
Send templated transactional email to one recipient.
Requires template defined on provider side. 
"""
usecase SendTemplatedEmail unsafe {
  input {
    """
    From
    The sender's email address.
    """
    from!

    """
    To
    The recipient's email address.
    """
    to!

    """
    Template Identifier
    The template to use when sending email message.
    """
    templateId!

    """
    Template Data
    Template data to be applied to the specified template to generate html, test, and subject.
    The value is a collection of key/value pairs following the pattern `variable_name`: `value to insert`.
    This field should be used in combination with `templateId` to identify what template to use.
    """
    templateData!
  }

  result {
    """
    Message Identifier
    The identifier is provider-specific and not unique.
    """
    messageId!
  }

  error {
    """
    Title
    A short, human-readable summary of the problem type.
    """
    title!

    """
    A human-readable explanation specific to this occurrence of the problem.
    """
    detail
  }

  example Successful {
    input {
      from = 'no-reply@example.com',
      to = 'jane.doe@example.com',
      templateId = 'user-invitation',
      templateData = {
        invited_by = 'Bob',
        invitation_link = 'example.com/invite?code=invite',
      },
    }

    result {
      messageId = 'gyax6ce9QLKQ80VOqsRX2g',
    }
  }

  example Failed {
    input {
      from = 'no-reply@example.com',
      to = 'Jane Doe',
      templateId = 'template-id',
      templateData = {
        template_data_param = 'value',
      },
    }

    error {
      title = 'Invalid inputs',
      detail = 'An email address must contain a single @',
    }
  }
}