
    @i~	                         d dl Z d dlZd dlmZ d dlmZmZ  e j                  e      Z G d d      Z	dde
fdZde
d	e
fd
Zy)    N)PhoneNumberFormat)format_datetime
to_pacificc                       e Zd Zed        Zy)AppointmentNotificationContextc                 R   | j                   j                  xs d}	 t        | j                        }t	        |      }|sd\  }}n|\  }}| j                  xs dt        | j                        |j                  t        d      d      || j                   j                  xs d||t        | j                        ||j                  dd      |j                  dd      |j                  d	d      d
S # t
        $ r0}t        j                  d|        | j                  }d}Y d }~d }~ww xY w)N
Dealership)NNzunable to parse in ctx N/AUnknowncustomer_numbermakemodelyear)customer_name	caller_idr   company
bdc_numberdatetimebooking_typedealership_namer   r   r   )r   namer   scheduled_dater   	Exceptionloggerwarningformat_phoneappointment_phonegetr   format_booking_typer   )appointmentextracompany_name
pacific_dt	formatteddate_strtime_stres           X/var/www/html/dp2/backend_v2.1/server/apps/appointments/services/notification_context.pybuildz$AppointmentNotificationContext.build
   s   "**//?<	#K$>$>?J'
3I%/"(%."( )--:%k&C&CD$yy6G)H%P#%--88AE/0H0HI+IIfe,YYw.IIfe,
 	
  	NN4QC89"11HH		s   -C- -	D&6&D!!D&N)__name__
__module____qualname__staticmethodr*        r)   r   r   	   s    
 
r0   r   numberc                 ,   | sy 	 t        j                  | |      }t        j                  |      s| S t        j                  |t        j
                        j                  dd      S # t        $ r$}t        j                  d|        | cY d }~S d }~ww xY w)N  zunbale to format phone number )
phonenumbersparseis_valid_numberformat_numberr   NATIONALreplacer   r   r   )r1   regionphoneexcs       r)   r   r   +   s    
""662++E2M))&&
 '#r
	  7u=>s"   ,A& 3A& &	B/BBBvaluereturnc                     | sy	 dj                  | j                         j                               }|j                         S # t        $ r$}t
        j                  d|        | cY d}~S d}~ww xY w)z
    Capitalizes the first letter of each word safely.
    Example:
        "oil change" -> "Oil Change"
        "  tire   rotation " -> "Tire Rotation"
    r
   r3   zUnable to format booking type: N)joinstripsplittitler   r   r   )r>   cleanedr=   s      r)   r    r    <   sa     ((5;;=..01}} 8>?s   <A 	A/A*$A/*A/)US)loggingr5   r   utils.timezone_utilsr   r   	getLoggerr+   r   r   strr   r    r/   r0   r)   <module>rK      sM      * <			8	$
 
D "s s r0   