# coding: utf-8
# Copyright (c) 2016, 2024, 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: 20220926

from __future__ import print_function
import click
import oci  # noqa: F401
import six  # noqa: F401
import sys  # noqa: F401
from oci_cli.cli_root import cli
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


@cli.command(cli_util.override('email_data_plane.email_data_plane_root_group.command_name', 'email-data-plane'), cls=CommandGroupWithAlias, help=cli_util.override('email_data_plane.email_data_plane_root_group.help', """Use the Email Delivery API to send high-volume and application-generated emails.
For more information, see [Overview of the Email Delivery Service]."""), short_help=cli_util.override('email_data_plane.email_data_plane_root_group.short_help', """Email Delivery Submission API"""))
@cli_util.help_option_group
def email_data_plane_root_group():
    pass


@click.command(cli_util.override('email_data_plane.email_submitted_response_group.command_name', 'email-submitted-response'), cls=CommandGroupWithAlias, help="""Response object that is returned to sender upon successfully submitting the email request.""")
@cli_util.help_option_group
def email_submitted_response_group():
    pass


email_data_plane_root_group.add_command(email_submitted_response_group)


@email_submitted_response_group.command(name=cli_util.override('email_data_plane.submit_email.command_name', 'submit-email'), help=u"""Submits a formatted email. \n[Command Reference](submitEmail)""")
@cli_util.option('--sender', required=True, type=custom_types.CLI_COMPLEX_TYPE, help=u"""""" + custom_types.cli_complex_type.COMPLEX_TYPE_HELP)
@cli_util.option('--recipients', required=True, type=custom_types.CLI_COMPLEX_TYPE, help=u"""""" + custom_types.cli_complex_type.COMPLEX_TYPE_HELP)
@cli_util.option('--subject', required=True, help=u"""A short summary of the content, which will appear in the recipient's inbox. UTF-8 supported [RFC 2047].""")
@cli_util.option('--message-id', help=u"""The unique ID for the email's Message-ID header used for service log correlation. The submission will return an error if the syntax is not a valid [RFC 5322] Message-ID. This will be generated if not provided. Example: sdiofu234qwermls24fd@mail.example.com""")
@cli_util.option('--body-html', help=u"""HTML body content in UTF-8. NOTE: Even though bodytext and bodyhtml are both optional, at least one of them must be provided.""")
@cli_util.option('--body-text', help=u"""Text body content. NOTE: Even though bodytext and bodyhtml are both optional, at least one of them must be provided.""")
@cli_util.option('--reply-to', type=custom_types.CLI_COMPLEX_TYPE, help=u"""The email address for the recipient to reply to. If left blank, defaults to the sender address.

This option is a JSON list with items of type EmailAddress.  For documentation on EmailAddress please see our API reference: https://docs.cloud.oracle.com/api/#/en/emaildp/20220926/datatypes/EmailAddress.""" + custom_types.cli_complex_type.COMPLEX_TYPE_HELP)
@cli_util.option('--header-fields', type=custom_types.CLI_COMPLEX_TYPE, help=u"""The header used by the customer for the email sent. Reserved headers are not allowed e.g \"subject\", \"from\", and \"to\" etc. Example: `{\"bar-key\": \"value\"}`""" + custom_types.cli_complex_type.COMPLEX_TYPE_HELP)
@json_skeleton_utils.get_cli_json_input_option({'sender': {'module': 'email_data_plane', 'class': 'Sender'}, 'recipients': {'module': 'email_data_plane', 'class': 'Recipients'}, 'reply-to': {'module': 'email_data_plane', 'class': 'list[EmailAddress]'}, 'header-fields': {'module': 'email_data_plane', 'class': 'dict(str, string)'}})
@cli_util.help_option
@click.pass_context
@json_skeleton_utils.json_skeleton_generation_handler(input_params_to_complex_types={'sender': {'module': 'email_data_plane', 'class': 'Sender'}, 'recipients': {'module': 'email_data_plane', 'class': 'Recipients'}, 'reply-to': {'module': 'email_data_plane', 'class': 'list[EmailAddress]'}, 'header-fields': {'module': 'email_data_plane', 'class': 'dict(str, string)'}}, output_type={'module': 'email_data_plane', 'class': 'EmailSubmittedResponse'})
@cli_util.wrap_exceptions
def submit_email(ctx, from_json, sender, recipients, subject, message_id, body_html, body_text, reply_to, header_fields):

    kwargs = {}
    kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(ctx.obj['request_id'])

    _details = {}
    _details['sender'] = cli_util.parse_json_parameter("sender", sender)
    _details['recipients'] = cli_util.parse_json_parameter("recipients", recipients)
    _details['subject'] = subject

    if message_id is not None:
        _details['messageId'] = message_id

    if body_html is not None:
        _details['bodyHtml'] = body_html

    if body_text is not None:
        _details['bodyText'] = body_text

    if reply_to is not None:
        _details['replyTo'] = cli_util.parse_json_parameter("reply_to", reply_to)

    if header_fields is not None:
        _details['headerFields'] = cli_util.parse_json_parameter("header_fields", header_fields)

    client = cli_util.build_client('email_data_plane', 'email_dp', ctx)
    result = client.submit_email(
        submit_email_details=_details,
        **kwargs
    )
    cli_util.render_response(result, ctx)
