o
    *g                     @   s>   d dl m Z  d dlmZmZmZ d dlmZ G dd dZdS )    )datetime)BuyerIntakeBuyerLocationBuyerIndustry)BuyerOutc                   @   s$   e Zd Zedd Zedd ZdS )BuyerIntakeServicec                    sn   |  |I dH   du rtd fdd|D }| |I dH   fdd|D }| |I dH   S )z
        Insert a new record into the financial_information_pages table using MySQLDB's execute_insert.

        :param db: An instance of MySQLDB
        :param kwargs: Dictionary of column values for the new record
        NzBFailed to insert buyer intake record. The returned object is None.c                    "   g | ]}t  j|d qS ))buyer_intake_idlocation
created_by)r   idupdate_modify).0locsaved_buyeruser_id 7/var/www/html/XCapMarket/services/buyer_intake/index.py
<listcomp>       z8BuyerIntakeService.insert_new_record.<locals>.<listcomp>c                    r   ))r	   industryr   )r   r   r   )r   indr   r   r   r   "   r   )execute_insert
ValueErrorexecute_bulk_insert)dbr   buyer_intake	locations
industriesbuyer_locationsbuyer_industriesr   r   r   insert_new_record   s   		z$BuyerIntakeService.insert_new_recordc                    s>   d}d|i}|  ||I dH }|du rdS dd |D }|S )z/
        Get a buyer intake form by id
        a  
            SELECT
                bif.*,
                GROUP_CONCAT(DISTINCT bl.location) AS locations,
                GROUP_CONCAT(DISTINCT bi.industry) AS industries
            FROM buyer_intake_form bif
            LEFT JOIN buyer_intake_locations bl ON bif.id = bl.buyer_intake_id
            LEFT JOIN buyer_intake_industries bi ON bif.id = bi.buyer_intake_id
            WHERE bif.id = :buyer_intake_id
            GROUP BY bif.id;
        r	   Nc              
   S   s   g | ]x}t d%i i d |d d|d d|d d|d d|d	 d
|d d|d d|d d|d d|d dt|d d|d d|d d|d d|d d|d d |d! rf|d! d"ng d#|d$ rt|d$ d"ng iqS )&r   r   
first_name   	last_name   email   phone   additional_info   	deal_size   revenue_multiple   ebidta_multiple   irr	   is_financing_needed
   
time_frame   
created_at   modified_at   r      modified_by   r      ,r      r   )r   boolsplit)r   rowr   r   r   r   F   sT    	
z<BuyerIntakeService.get_buyer_intake_form.<locals>.<listcomp>)execute)r   r	   queryvaluesresultbuyer_out_instancesr   r   r   get_buyer_intake_form/   s   z(BuyerIntakeService.get_buyer_intake_formN)__name__
__module____qualname__staticmethodr"   rK   r   r   r   r   r      s
    
'r   N)r   models.buyer_intaker   r   r   schemas.buyer_intake_formr   r   r   r   r   r   <module>   s    