o
    Q?h                     @   s   d dl Z d dlZd dlmZmZmZ d dlmZ d dlm	Z	 d dl
mZ dZdZdefd	d
ZdefddZd dlZdefddZdd Zdd Zdd ZdS )    N)ArrayRemove
ArrayUniondb)	API_Error)getBlankVariantPrice)ParamsXR7pJeG12SlLSMYGW2SRHvUN prj_IwBIAM0rRp7aC9AJwAPRlIXpNG4cparamsc                    sv   | j }|j}| jd td|  }|dg }td|d g fdd|D  i d |dS )Ndomainenterprises	hostnamesc                    s   g | ]}| kr|qS  r   ).0withoutr   r   J/var/www/html/riverr-enterprise-integrations-main/functions/Enterprises.py
<listcomp>   s    z$addPrimaryDomain.<locals>.<listcomp>success)statusprimaryDomainr   )	currentUserenterpriseIdargsgetr   
collectiondocumentto_dictupdate)r
   r   r   
enterpriseexistingDomainsr   r   r   addPrimaryDomain   s   r!   c                 C   s:  | j }|j}| jd}| jd}tddd| }|r%tdddt d	}d
t	 dd}|D ]e}||d}	zDt
j|||	d}
|
  |
jdv r|
 }|dshtd|dt|gi ntd|dt|gi |
 W   S W q5 t
jjy } zt| W Y d }~ d S d }~ww d S )Ndomainsr   r   r   array_contains_anyzDomain already existsi  #https://api.vercel.com/v1/projects/z/domainsBearer application/jsonAuthorizationzContent-Type)nameredirect)headersjson      verifiedpendingHostnames)r   r   r   r   r   r   wherer   
project_id	api_tokenrequestspostraise_for_statusstatus_coder,   r   r   r   
exceptionsRequestExceptionprint)r
   r   r   r"   r   queryurlr+   r   payloadresponsedataer   r   r   addCustomDomain   sB   


	rB   c              
   C   s   | j d}dt d| d}dt dd}| jj}z0tj||d}|  |j	d	v rG|
 d
rGtd| t|gt|gd |
 W S  tjjyn } zt|dt v r`|j	nddW  Y d}~S d}~ww )a
  
    Verifies a custom domain in a Vercel project.
    
    :param api_token: str - The Vercel API token.
    :param project_id: str - The Vercel project ID.
    :param domain: str - The custom domain to verify.
    :return: dict - Response from the Vercel API.
    r   r$   z	/domains/z/verifyr%   r&   r'   )r+   r-   r0   zenterprises/)r   r1   r?   N)errorr8   )r   r   r3   r4   r   r   r5   r6   r7   r8   r,   r   r   r   r   r   r9   r:   strlocals)r
   r   r=   r+   r   r?   rA   r   r   r   verifyCustomDomain=   s(   	

*rF   c                 C   s$   t ddd|  }|d  S )Nr   r   array_containsr   )r   r   r2   r   r   )hostnamerefr   r   r   getEnterpriseByHostname[   s   rJ   c                 C   s   t d|  }| S )Nr   )r   r   r   r   r   )r   rI   r   r   r   getEnterpriseById_   s   rK   c           
   
   C   s  zsd}d}d}t d| d|  }|s"td| | n|di }|d|di }|dd}|d	d}|rHt|ttfvrJd}t	||| }t|ttfvrZd}|d u r`d}t
t|t| t|| d
  dW S  ty }	 ztt  W Y d }	~	dS d }	~	ww )Nr   r   blankProductszno blank settings
placements12printingPriceupcharged      )r   r   r   r   r   r;   typeintfloatr   round	Exception	traceback
format_exc)
r   blankProductIdblankVariantId
printPriceblankVariantPricerQ   blankSettingsrM   	placementrA   r   r   r   getItemCostc   s*   $(ra   )rY   r5   configs.firebaser   r   r   functions.Responser   functions.Suppliers.Pricingr   	V2.Paramsr   r4   r3   r!   rB   rF   rJ   rK   ra   r   r   r   r   <module>   s    !