
    $1i?R                        d dl m Z mZ d dlmZmZ d dlmZ d dlmZ d dl	m
Z
mZmZmZmZ d dlmZ d dlmZmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dl m!Z!m"Z" d dl#m$Z$ d dl%m&Z& d dl'm(Z(  G d de      Z) G d de      Z* G d de      Z+ G d de      Z, G d de      Z- G d de      Z. G d de      Z/ G d  d!e      Z0 G d" d#e      Z1 G d$ d%e      Z2 G d& d'e      Z3 G d( d)e      Z4 G d* d+e      Z5y,)-    )datetime	timedelta)OptionalList)Query)EmailStr)Field	BaseModelfield_validatormodel_validator
ConfigDict)UserBase)PaymentMethodTypesAccountsBulkActions)PaymentAuthorizationTypes)regexp)AddressCreateRequestSchema)
FileCreate)"CustomerContactCreateRequestSchema)CustomerBase)selectand_)SessionLocal)Customer)Merchantc            
           e Zd ZU  eddddddddi	      Z ed
      Zeed<    ed      Z	e
ed<    edd      Zee   ed<    edd      Zee   ed<   y) CustomerOwnerCreateRequestSchemaTexamplejohndoe@example.comweakpassword+9176787678JohnDoeemailpasswordphone
first_name	last_namefrom_attributesjson_schema_extraA valid email addressdescriptionr%   A valid phone numberr'   NzBActivation status of user, false denotes that the user is inactivedefaultr/   	is_activezFVerification status of user, false denotes that the user is unverifiedis_verified)__name__
__module____qualname__r   model_configr	   r%   r   __annotations__r'   strr3   r   boolr4        j/var/www/html/hwPaymentPortal-be-dev/hw-payment-portal-api/src/apps/customers/schemas/customer_requests.pyr   r      s    .*&$"
L (?@E8@#9:E3: %X!Ix~  #(\#K$ r=   r   c                      e Zd ZU  eddi ddddddd	d
dddddddddddddddddddgdddd d!d"d#d$d%d&d'd(d)d*dd+d,d-d.d/d0d1d2d3ii4      Z ed5d67      Zee   e	d,<    ed5d87      Z
eee      e	d9<    ed:;      Zee	d#<    ed5d<7      Zee   e	d=<    ed> ?      Zee	d@<    ed5dA7      Zee   e	d	<    ed5dB7      Zee   e	d<    ed5dC7      Zee   e	d<    ed5dD7      Zee   e	d<    ed5dE7      Zee   e	d<    ed5dF7      Zee   e	d<    ed5dG7      Zee   e	d<    ed5dHdIdIJ      Zee   e	d!<    ed5dK7      Zee   e	d<    edL;      Zee	d<    eddM7      Zee   e	d<    ed5dN7      Z ee   e	d<    ed5dO7      Z!eee      e	d<    ed5dP7      Z"ee   e	d<    ed5dQ7      Z#ee   e	d<    eddR7      Z$ee   e	d<    e%d!      e&dS               Z' e(dTU      dV        Z)y5)WCustomerCreateRequestSchemaTr   r(   r"   middle_nameMichaelr)   r#   r%   zjohn.doe@example.comr'   z+1234567890office_phonez+1987654321business_legal_namezDoe Industries LLCcustomer_typezBusiness Customer	is_vendorF	role_typezPrimary ContacttimezonezAmerica/New_Yorkr3   tagspremiumb2bmerchant_id   user_account_id{   account_literalACC123456789012addressz123 Business Avenuez	Suite 40010001zNew YorkNYUSbillingaddress_line_1address_line_2zipcodecitystatecountryaddress_typeuse_as_defaultcontactJaneSmithzjane.smith@example.comz+1555123456zAccount Managerprimaryr(   r)   r%   account_phonetitlerelationr*   N8A new contact for this customer that needs to be createdr1   z#Multiple contacts for this customercontactsz%Customer's billing address (required)r.   z+Uploaded image file id to be used as avataravatarc                  D    t        j                         t        d      z   S )Ni!  )days)r   nowr   r<   r=   r>   <lambda>z$CustomerCreateRequestSchema.<lambda>h   s    R[biRkAk r=   )default_factoryaccount_expires_onr-   r0   First name of the customerMiddle name of the customerLast name of the customerOffice Phone of the customerLegal name of the businessUser-provided account literal (15 characters). If not provided, system will auto-generate one. This is the public-facing account number.   r2   r/   
min_length
max_lengthRole type of the Customer:Customer type: any string value to categorize the customerz<Vendor type of the customer (auto-set based on account_type)A valid timezoneTags of customerID of the merchantID of the user accountzJActivation status of customer, false denotes that the customer is inactivec                 r    |4|j                         st        d      t        |      dk7  rt        d      |S z,Validate account literal format if provided.z9Account literal must contain only alphanumeric charactersrw   z2Account literal must be exactly 15 characters longisalnum
ValueErrorlenclsvs     r>   validate_account_literal_formatz;CustomerCreateRequestSchema.validate_account_literal_format   :     =99; !\]]1v| !UVVr=   after)modec           
         t               5 }| j                  rt        t              j	                  t        t        j                  | j                  k(  t        t        d      rt        j                  j                  d      nd            }|j                  |      j                         rt        d      | j                  rqt        t              j	                  t        j                  | j                  k(        }|j                  |      j                         st        d| j                   d      | j                  roddlm} t        |      j	                  |j                  | j                  k(        }|j                  |      j                         st        d	| j                   d      | j$                  rqt        t              j	                  t        j$                  | j$                  k(        }|j                  |      j                         rt        d
| j$                   d      ddd       | S # 1 sw Y   | S xY w)z,Validate customer data with database checks.
deleted_atNTz'Customer with this email already existszMerchant with ID z does not existr   )UserzUser account with ID zAccount literal 'z' already exists. Please choose a different account literal or use the /customers/account-suggestions endpoint for suggestions.)r   r%   r   r   wherer   hasattrr   is_executescalar_one_or_noner   rL   r   idrN   src.apps.users.models.userr   rP   )selfdb
email_stmtmerchant_stmtr   	user_stmtliteral_stmts          r>   validate_customer_dataz2CustomerCreateRequestSchema.validate_customer_data   s    ^ !	rzz#H-33 $**49@<9X++//5^b
 ::j)<<>$%NOO  &x 0 6 6x{{dFVFV7V Wzz-0CCE$'89I9I8J/%Z[[ ##;"4L..tww$:N:N/NO	zz),??A$'<T=Q=Q<RRa%bcc ##%h/55h6N6NRVRfRf6fg::l+>>@$+D,@,@+A BH H =!	F G!	F s   HH33H=)*r5   r6   r7   r   r8   r	   r`   r   r   r9   ri   r   rR   r   rj   intrp   r   r%   r   r'   r:   r(   rA   r)   rC   rD   rP   rG   rE   rF   r;   rH   rI   rL   rN   r3   r   classmethodr   r   r   r<   r=   r>   r@   r@   .   sx    #f#y# U# /	#
 # # &';#  !4# U# .# .# T# E*# q# "3#  "#4!#" &;&1&&!#$-&*	##6 "(!(5%2. )7#%
(LT =BN=GX89  DI9DHht>?@  +0;+G'  "AFHSM  $)9k#ll %d@W XE8HX ;QRE8C=R %d@\ ]J]!&tA^!_K#_$T?Z[Ix}["'B`"aL(3-a).tIe)f#f%* _	&OXc]   %T?Z[Ix}[PM3  !&R!Ix~  $D>PQHhsmQ %d@R SD(49
S!&tAU!VK#V%*4E]%^OXc]^ %`!Ix~ 
 &'  ( '"& #&r=   r@   c                      e Zd ZU  eddi ddddddd	d
dddddddddddddddddg dddddd d!d"d#d$d%d&d'd(d)dd*d+d,d-d.d/d0d1d2ii3      Z ed4d56      Zee   e	d<    ed4d76      Z
ee   e	d<    ed4d86      Zee   e	d<    ed4d96      Zee   e	d	<    ed4d:6      Zee   e	d<    ed4d;6      Zee   e	d<    ed4d<6      Zee   e	d<    ed4d=6      Zee   e	d<    ed4d>6      Zee   e	d<    edd?6      Zee   e	d<    ed4d@6      Zee   e	d"<    ed4dA6      Zee   e	d+<    ed4dB6      Zee   e	dC<    ed4dD6      Zeee      e	d<    ed4dE6      Zee   e	d<    ed4dF6      Zee   e	d<    ed4dG6      Zee   e	d<    ed4dH6      Zee   e	d<    ed4dIdJdJK      Z ee   e	d <    e!d       e"dL               Z#y4)MCustomerUpdateRequestSchemaTr   r(   zUpdated JohnrA   zUpdated Michaelr)   zUpdated Doer%   zupdated.john.doe@example.comr'   z+1234567891rC   z+1987654322rD   zUpdated Doe Industries LLCrE   zUpdated Business TyperF   rG   zUpdated RolerH   zAmerica/Los_Angelesr3   FrI   )updatedrJ   
enterpriserL      rN   i  rP   UPD123456789012rR   z456 Updated StreetzFloor 590210zLos AngelesCArU   shippingrW   r`   zUpdated JanezUpdated Smithzupdated.jane@example.comz+1555654321zSenior Manager	secondaryrd   r*   Nrq   r1   rr   rs   zEmail of the customerzPhone of the customerrt   ru   zJActivation status of Customer, false denotes that the Customer is inactiver|   zWBoolean flag indicating if this entity is a vendor (independent of customer_type field)z8A new address for this customer that needs to be createdrh   z.ID of Uploaded image file to be used as avatarrj   r~   r{   r}   r   r   rv   rw   rx   c                 r    |4|j                         st        d      t        |      dk7  rt        d      |S r   r   r   s     r>   r   z;CustomerUpdateRequestSchema.validate_account_literal_format  r   r=   )$r5   r6   r7   r   r8   r	   r(   r   r:   r9   rA   r)   r%   r'   rC   rD   r3   r;   rE   rF   rR   r   r`   r   rj   r   rI   r   rG   rH   rL   rN   rP   r   r   r   r<   r=   r>   r   r      s3    #n#0# ]# 7	#
 # # &'C#  !8# T# ^# 1# U# <# q# "3#  "#4!#" &:&/&)!#$.&+	##6 "0!07%2- +7#%
(LT !&d@\ ]J]!&tA^!_K#_$T?Z[Ix}[ ;RSE8C=S ;RSE8C=S"'B`"aL(3-a).tIe)f#f %`!Ix~  $)P$M8C=  !&m!Ix~  5:N5GX01  =BN=GX89  "DFHSM  !&d@R SD(49
S  %T?Z[Ix}[#D>PQHhsmQ!&tAU!VK#V%*4E]%^OXc]^%* _	&OXc]  &'  (r=   r   c                      e Zd ZU  edd      Zee   ed<    edd      Zee   ed<    edd      Z	ee   ed<    edd	      Z
ee   ed
<    edd      Zee   ed<    edd      Zee   ed<    edd      Zee   ed<    ed      Zee   ed<    edd      Zee   ed<    edd      Zee   ed<    edd      Zee   ed<   y)CustomerListFilterSchemaNz2Search by name, email, phone, city, state, zip etcr1   searchzSearch by addressrR   zSearch by city namer[   z;Search by comma separated list of states. Eg.: ?state=AR,AZr\   zSearch by zipcoderZ   z@Search by comma separated list of countries. Eg.: ?country=US,CAr]   r   zActive status of customerr3   F)r2   rF    zname of the customernamezphone of the customerr'   zemail of the customerr%   )r5   r6   r7   r   r   r   r:   r9   rR   r[   r\   rZ   r]   r3   r   rF   r;   r   r'   r%   r<   r=   r>   r   r   "  s   !"VFHSM  #4=PQGXc]Q:OPD(3-P QE8C=  #4=PQGXc]Q"VGXc]   %Q<WXIx}X %e 4Ix~48NOD(3-O 9PQE8C=Q 9PQE8C=Qr=   r   c                       e Zd ZU  edd      Zee   ed<    edej                  d      Z
ee   ed<    edej                  d      Zee   ed	<    edd
      Zee   ed<   y) CustomerTransactionsFilterSchemaN@Search by customer name, email, transaction billing address, etcr1   r   z>Start date of listing to be done. Must be of format YYYY-MM-DD)r2   patternr/   	date_fromz<End date of listing to be done. Must be of format YYYY-MM-DDdate_toz-Comma separated list of status of transactionstatus)r5   r6   r7   r   r   r   r:   r9   r   ISO_DATE_FORMATr   r   r   r<   r=   r>   r   r   8  s    !VFHSM   %&&T Ix} 
 #&&RGXc] 
 ""QFHSM r=   r   c                       e Zd ZU  edd      Zee   ed<    edd      Zee   ed<    edd      Z	ee   ed<    edd	      Z
ee   ed
<    edd      Zee   ed<    edd      Zee   ed<   y)CustomerInvoicesFilterSchemaNr   r1   r   zESearch by comma separated list of currencies. Eg.: ?currency=usd,yuancurrencyzSearch by the unique invoice id
invoice_idzTSearch by comma separated list of frequencies. Eg.: ?payment_frequeny=split,one_timepayment_frequencyzSearch by authorisation typeauthorization_typezOSearch by comma separated list of status. Eg.: ?status=paid,full_amount_pendingr   )r5   r6   r7   r   r   r   r:   r9   r   r   r   r   r   r   r<   r=   r>   r   r   L  s    !VFHSM  $[Hhsm  !&"C!J  (-j(x}  ?D"@?!:;  "eFHSM r=   r   c                   r    e Zd ZU  ed      Zeed<    ed      Zee	   ed<    e
d      ed               Zy)CustomerAccountBulkActionsz+Type of action which needs to be performed.r.   actionzJAn array of customer_ids of the items that you want to perform actions foridsc                     d}|t        |      dk(  rt        d      t        |      |kD  rt        d| d      |D ]5  }t        j                  |t        j                        r(t        d| d       |S )N
   r   z'Please provide atleast one customer idszYou can provide atmost of z customer ids at once'z' is not a valid customer ids)r   r   r   testCUSTOMER_UNIQUE_ID)r   r   	max_limititems       r>   validate_idsz'CustomerAccountBulkActions.validate_idsm  s     	9A!FHHq6I,YK7LM   	JD;;tV%>%>? 1TF*G!HII	J r=   N)r5   r6   r7   r	   r   r   r9   r   r   r:   r   r   r   r<   r=   r>   r   r   e  sR    "'A#F  `Cc  U  r=   r   c                   V    e Zd ZU  edd      Zee   ed<    edd      Zee	   ed<   y)"CustomerPaymentMethodsFilterSchemaNz;Search by card number, card expiry, ach account number, etcr1   r   zSearch by payment method typemethod)
r5   r6   r7   r   r   r   r:   r9   r   r   r<   r=   r>   r   r   }  s<    !QFHSM  ,1"A,FH'( r=   r   c            
           e Zd ZU  eddddddddi	      Z ed
      Zeed<    ed      Z	e
ed<    edddd      Zee
   ed<    edddd      Zee
   ed<   defdZy)"CustomerAccountCreateRequestSchemaTr   r   r    r!   r"   r#   r$   r*   r-   r.   r%   r0   r'   N       z'Make sure you choose a strong password.)r2   ry   rz   r/   r&   z!Make sure the passwords are same.confirm_passwordreturnc                 4    | j                   | j                  k(  S )N)r&   r   )r   s    r>   compare_passwordsz4CustomerAccountCreateRequestSchema.compare_passwords  s    }} 5 555r=   )r5   r6   r7   r   r8   r	   r%   r   r9   r'   r:   r&   r   r   r;   r   r<   r=   r>   r   r     s    .*&$"
L (?@E8@#9:E3:#=	Hhsm  ',7	'hsm 64 6r=   r   c                   2    e Zd ZU dZ eddd      Zeed<   y)CustomerActionRequestSchemaz:Schema for customer action requests (activate/deactivate)..zAction to perform on customerz^(activate|deactivate)$r/   r   r   N)r5   r6   r7   __doc__r	   r   r:   r9   r<   r=   r>   r   r     s    D)HRklFClr=   r   c                   |    e Zd ZU dZ edddg ddi      Z edd	d
      Zee	d<    edddd      Z
ee   e	d<   y)CustomerBulkActionRequestSchemazNSchema for bulk customer actions. Limited to maximum 10 customers per request.Tr   activate)ACCROS171217C9BACCABI03758427FACCXYZ123456789)r   r   r*   .zAction to perform on customersz^(activate|deactivate|delete)$r   r   zBList of customer IDs to perform action on (maximum 10 per request)rM   r   )r/   ry   rz   r   N)r5   r6   r7   r   r   r8   r	   r   r:   r9   r   r   r<   r=   r>   r   r     sf    X$	
L 40FC 
 X	Cc r=   r   c                   j    e Zd ZU dZ ed      Z edddd      Zee	d<    eddd	d
d      Z
ee	d<   y)CustomerPaginationSchemaz!Schema for pagination parameters.Tr+   rM   zPage number for pagination)ger/   r   page   d   z"Number of items per page (max 100))r   ler/   r   per_pageN)r5   r6   r7   r   r   r8   r	   r   r   r9   r   r<   r=   r>   r   r     s?    +d3LaA+GQRSD#S"s8\fhiHcir=   r   c                      e Zd ZU dZ ed      Z eddd      Zee	   e
d<    edd	d
      Zee	   e
d<    eddd      Zee	   e
d<    eddd      Zee	   e
d<    eddd      Zee	   e
d<    eddd      Zee	   e
d<    eddd      Zee	   e
d<    eddd      Zee	   e
d<    eddd      Zee	   e
d <    ed!d"d#      Zee
d$<    ed!d%d&      Zee
d'<    edd(d)      Zee	   e
d*<   y)+CustomerFilterSchemaz/Schema for consolidating customer list filters.Tr   NzASearch across customer name, email, customer_id, or business namejohn)r/   r   r   z5Filter by customer first or last name (partial match)r"   r   z0Filter by customer email address (partial match)zjohn@example.comr%   z/Filter by customer phone number (partial match)z123-456-7890r'   zAFilter by customer address (searches address_line_1, city, state)zMain StreetrR   z+Filter by customer zip code (partial match)12345zip_codez*Filter by customer type (any string value)BusinessrE   zFilter by account/business typeLLCaccount_typez"Filter by industry (partial match)financeindustryr   zDFilter by active status: 0=show all, 1=active only, -1=inactive onlyrM   r3   zFFilter by vendor status: 0=show all, 1=vendors only, -1=customers onlyrF   z]Comma-separated list of related fields to include: addresses, contacts, merchant, attachmentszaddresses,contactsfields)r5   r6   r7   r   r   r8   r	   r   r   r:   r9   r   r%   r'   rR   r   rE   r   r   r3   r   rF   r   r<   r=   r>   r   r     s^   9d3L!$4w  BH  IFHSM  I2isyzD(3-z 3e  pB  CE8C=  C 3dn|}E8C=}"45x  CP  QGXc]  Q#D6cmtuHhsmu#(;gq{#|M8C=|"':[ej"kL(3-k#D6ZdmnHhsmn1*pz{|Is|1*r|~Is!$  5T  ^r  sFHSM  sr=   r   N)6r   r   typingr   r   fastapi.param_functionsr   pydantic.networksr   pydanticr	   r
   r   r   r   "src.apps.users.schemas.user_commonr   src.core.utils.enumsr   r   src.apps.payment_requests.enumsr   src.apps.base.utilsr   src.apps.base.schemas.commonr   $src.apps.files.schemas.file_requestsr   +src.apps.customers.schemas.customer_contactr   *src.apps.customers.schemas.customer_commonr   
sqlalchemyr   r   src.core.databaser   "src.apps.customers.models.customerr   "src.apps.merchants.models.merchantr   r   r@   r   r   r   r   r   r   r   r   r   r   r   r<   r=   r>   <module>r     s    ( ! ) & S S 7 H E & C ; Z C # * 7 7x 4K, K^a, aJRy R,y (9 2 0 6 6Bm) m
i :jy js9 sr=   