o
    w+f                     @   s   G d d de ZdS )c                   @   sl  e Zd ZdZdd Zdd Zdd Zedd	 Zej	d
d	 Zdd Z
edd Zej	dd Zdd Zedd Zej	dd Zdd Zedd Zej	dd Zdd Zedd Zej	dd Zedd  Zej	d!d  Zd"d# Zed$d% Zej	d&d% Zd'd( Zed)d* Zej	d+d* Zd,d- Zed.d/ Zej	d0d/ Zed1d2 Zej	d3d2 Zd4d5 Zd6S )7PersonalizationzsA Personalization defines who should receive an individual message and
    how that message should be handled.
    c                 C   s@   g | _ d| _g | _g | _d| _g | _g | _g | _d| _d| _	dS )z@Create an empty Personalization and initialize member variables.N)
_tos_from_email_ccs_bccs_subject_headers_substitutions_custom_args_send_at_dynamic_template_dataself r   X/var/www/html/venv/lib/python3.10/site-packages/sendgrid/helpers/mail/personalization.py__init__   s   
zPersonalization.__init__c                 C   sl   t |}|jdkr| | d S |jdkr| | d S |jdkr(| | d S |jdkr2|| _d S td)NToCcBccFromz(Please use a To, From, Cc or Bcc object.)type__name__add_toadd_ccadd_bcc
from_email
ValueError)r   email
email_typer   r   r   	add_email   s   






zPersonalization.add_emailc                    sh   g }|D ]-}t |tr|d  n|j  t fdd|D r1t |tr(|n| }|| q|S )Nr   c                 3   s     | ]}|d     kV  qdS )r   N)lower).0unique_recipientrecipient_emailr   r   	<genexpr>(   s    
z9Personalization._get_unique_recipients.<locals>.<genexpr>)
isinstancedictr   r   allgetappend)r   
recipientsunique_recipients	recipientnew_unique_recipientr   r"   r   _get_unique_recipients#   s    
z&Personalization._get_unique_recipientsc                 C      |  | jS )zSA list of recipients for this Personalization.

        :rtype: list(dict)
        )r.   r   r   r   r   r   tos1      zPersonalization.tosc                 C   
   || _ d S N)r   r   valuer   r   r   r0   9      
c                 C   s   |j rt|j tr|j D ]}| | qn| |j  |jr"|j| _|jr6t|jtr0|j| _n|j | _| j	|  dS )zTAdd a single recipient to this Personalization.

        :type email: Email
        N)
substitutionsr%   listadd_substitutiondynamic_template_datasubjectstrr(   r   r)   )r   r   substitutionr   r   r   r   =   s   

zPersonalization.add_toc                 C      | j S r3   r   r   r   r   r   r   T   s   zPersonalization.from_emailc                 C   r2   r3   r?   r4   r   r   r   r   X   r6   c                 C   s   |  | _d S r3   )r(   r   r   r   r   r   r   set_from\   s   zPersonalization.set_fromc                 C   r/   )z`A list of recipients who will receive copies of this email.

        :rtype: list(dict)
        )r.   r   r   r   r   r   ccs_   r1   zPersonalization.ccsc                 C   r2   r3   )r   r4   r   r   r   rB   g   r6   c                 C      | j |  dS )zAdd a single recipient to receive a copy of this email.

        :param email: new recipient to be CCed
        :type email: Email
        N)r   r)   r(   r@   r   r   r   r   k      zPersonalization.add_ccc                 C   r/   )zmA list of recipients who will receive blind carbon copies of this email.

        :rtype: list(dict)
        )r.   r   r   r   r   r   bccss   r1   zPersonalization.bccsc                 C   r2   r3   )r   r4   r   r   r   rE   {   r6   c                 C   rC   )zAdd a single recipient to receive a blind carbon copy of this email.

        :param email: new recipient to be BCCed
        :type email: Email
        N)r   r)   r(   r@   r   r   r   r      rD   zPersonalization.add_bccc                 C   r>   )zThe subject of your email (within this Personalization).

        Char length requirements, according to the RFC:
        https://stackoverflow.com/a/1592310

        :rtype: string
        r   r   r   r   r   r;      s   	zPersonalization.subjectc                 C   r2   r3   rF   r4   r   r   r   r;      r6   c                 C   r>   )zTThe headers for emails in this Personalization.

        :rtype: list(dict)
        r   r   r   r   r   headers      zPersonalization.headersc                 C   r2   r3   rG   r4   r   r   r   rH      r6   c                 C   rC   )zSAdd a single Header to this Personalization.

        :type header: Header
        N)r   r)   r(   )r   headerr   r   r   
add_header      zPersonalization.add_headerc                 C   r>   )z]Substitutions to be applied within this Personalization.

        :rtype: list(dict)
        r   r   r   r   r   r7      rI   zPersonalization.substitutionsc                 C   r2   r3   rM   r4   r   r   r   r7      r6   c                 C   s"   t |ts	| }| j| dS )zbAdd a new Substitution to this Personalization.

        :type substitution: Substitution
        N)r%   r&   r(   r   r)   )r   r=   r   r   r   r9      s   
z Personalization.add_substitutionc                 C   r>   )ziThe CustomArgs that will be carried along with this Personalization.

        :rtype: list(dict)
        r	   r   r   r   r   custom_args   rI   zPersonalization.custom_argsc                 C   r2   r3   rN   r4   r   r   r   rO      r6   c                 C   rC   )zVAdd a CustomArg to this Personalization.

        :type custom_arg: CustomArg
        N)r	   r)   r(   )r   
custom_argr   r   r   add_custom_arg   rL   zPersonalization.add_custom_argc                 C   r>   )zA unix timestamp allowing you to specify when you want emails from
        this Personalization to be delivered. Scheduling more than 72 hours in
        advance is forbidden.

        :rtype: int
        r
   r   r   r   r   send_at   s   zPersonalization.send_atc                 C   r2   r3   rR   r4   r   r   r   rS      r6   c                 C   r>   )zData for dynamic transactional template.
        Should be JSON-serializable structure.

        :rtype: JSON-serializable structure
        )r   r   r   r   r   r:      s   z%Personalization.dynamic_template_datac                 C   s   t |ts	| }|| _d S r3   )r%   r&   r(   r   r4   r   r   r   r:      s   

c                 C   s   i }dD ]}t | |}|r|||dd < qt | d}|r!||d< dD ]}t | |}|r0|||< q#dD ]}t | |}|rLi }|D ]}|| |||< q@q3|S )z
        Get a JSON-ready representation of this Personalization.

        :returns: This Personalization, ready for use in a request body.
        :rtype: dict
        )r0   rB   rE   Nr   from)r;   rS   r:   )rH   r7   rO   )getattrupdate)r   personalizationkeyr5   
from_value	prop_namepropobjr   r   r   r(      s.   





zPersonalization.getN)r   
__module____qualname____doc__r   r   r.   propertyr0   setterr   r   rA   rB   r   rE   r   r;   rH   rK   r7   r9   rO   rQ   rS   r:   r(   r   r   r   r   r      sj    


















	


r   N)objectr   r   r   r   r   <module>   s    