o
    g|/                     @   s   d Z ddlZddlZddlZ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mZ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 ZG dd deddZG dd deddZG dd deddZdS )zProject class structure    N)AnyDictOptional)uuid4)	BaseModelFieldroot_validator	validator)CompanyProfileMaker)CompanyInfo)SlideContent)DynamoDB)
parsed_urlc                 C   s`   dd | j  D }i }t|D ]}||vr'|| dur'|dkr'||||< q|i kr.|S dS ) add extra information if needed.c                 S   s   h | ]
}|j d kr|j qS extra)alias).0field r   G/var/www/html/XCapMarket/services/ppt_generator/data_classes/project.py	<setcomp>   s    zbuild_extra.<locals>.<setcomp>Nr   )
__fields__valueslistpop)clsr   all_required_field_namesr   
field_namer   r   r   build_extra   s   r   c                	   @   s6  e Zd ZU dZedd ddZ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d< eddd	Z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< edddZeed< edddZeed< ed d!ed"d# Zed$ed%ed&ed'efd(d)Zd*d+ ZdS ),SlidezSlide structure.c                   C      t t jS Nstrr   hexr   r   r   r   <lambda>&       zSlide.<lambda>zThe UUID of the slidedefault_factorytitleuuid.zThe title of the slider*   r*   zThe content of the slidecontentz'Data required for the slide to completedatazDesign for the powerpoint slide with respect to the data
         and content assume a 16:9 aspect ratio and 1920x1080 resolution.designz5Questions needed to be answered to complete the slide	questionsz%The order of the slide in the sectionslide_orderNzSlide content structuredefaultr*   content_layoutzThe research done for the slideresearchFzWhether the slide is newisNewzWhether the slide is updated	isUpdatedTprec                 C      t | ||d< |S r   r   r   r   r   r   r   r   r   ?      zSlide.build_extra
project_id
section_idslide_idreturnc                 C   s   | d | d | S )N-r   )r?   r@   rA   r   r   r   build_slide_research_idF   s   zSlide.build_slide_research_idc                 C   s&   t  }||d| j}|ddS )z$Get the research done for the slide.slide_researchr5    )r   get_item	get_tabler5   get)selfdbitemr   r   r   get_slide_researchJ   s   zSlide.get_slide_research)__name__
__module____qualname____doc__r   r+   r$   __annotations__r*   r-   r.   r/   r0   r   r1   intr4   r   r5   r   r6   boolr7   r   classmethodr   staticmethodrD   rM   r   r   r   r   r    "   s@   
 r    allowr   c                   @   s   e Zd ZU dZedd ddZeed< eddd	Zeed
< edddZ	e
e dB ed< eddd	Zeed< edddZedB ed< edddZeed< edddZeed< eddedd ZdS )SectionzSection structure.c                   C   r!   r"   r#   r   r   r   r   r&   U   r'   zSection.<lambda>zThe UUID of the sectionr(   r+   .zThe title of the sectionr,   r*   NzDlist of slides for the section, include 3 or more slides per sectionr2   slidesz,The order of the section in the presentationsection_orderzThe content of the sectionr-   FzWhether the section is newr6   zWhether the section is updatedr7   Tr8   c                 C   r:   r;   r<   r=   r   r   r   r   c   r>   zSection.build_extra)rN   rO   rP   rQ   r   r+   r$   rR   r*   rY   r   r    rZ   rS   r-   r6   rT   r7   r   rU   r   r   r   r   r   rX   Q   s&   
 rX   c                   @   s  e Zd ZU dZedddZeed< edddZeed	< edd
dZ	eed< eg ddZ
ee dB ed< edddZedB ed< edddZedB ed< edddZedB ed< edddZedB ed< edddZedB ed< eg ddZedB ed< edddZedB ed< edddZee dB ed< edd dZee ed!< edd"dZee dB ed#< edd$dZee dB ed%< edd&dZedB ed'< e ZedB ed(< ej d)ZedB ed*< e Z edB ed+< ej d)Z!edB ed,< edd-dZ"e#dB ed.< edd/dZ$edB ed0< dLd2e%fd3d4Z&d5d6 Z'e(dd7d8e)d9d: Z*e+d7d;e)d<d= Z,e-dMdefd>d?Z.d@dA Z/e)dBdC Z0e+e)dDdE Z1e)d#ee fdFdGZ2e)dHdI Z3dJdK Z4dS )NProjectzProject structure..zThe project idr,   r?   NzThe company urlr2   company_urlzThe company namecompany_namezThe company alternative namescompany_alt_nameszThe final ppt pathfinal_ppt_pathzThe industry of the companyindustryzThe sector of the companysectorprivatez The public status of the companypublic_statuszThe pitch type of the project
pitch_typezThe financials for the companycompany_financialsactivez;The status of the project (i.e.: active, archived, deleted)statuszThe team members of the projectteam_membersz$list of sections in the presentationsectionszThe targets for the projecttargetsz The public comps for the projectpublic_compszThe client of the projectclient
created_by%Y-%m-%d %H:%M:%Screated_datemodified_bymodified_datezThe project detailsproject_detailszThe pitch date of the project
pitch_dateFinclude_project_infoc                 C   sF   |r	t |  S t | j| j| j| j| j| j| j	| j
| j| jd
S )z$Convert the company info to a string)
r]   r\   r`   ra   rc   rd   r^   re   rs   rr   )jsondumpsdictr]   r\   r`   ra   rc   rd   r^   re   rs   rr   )rJ   rt   r   r   r   stringify_company_info   s   zProject.stringify_company_infoc                 C   s    t  | _tj d| _dS )z(Update the modified date and modified byrn   N)socketgethostnamerp   datetimenowstrftimerq   )rJ   r   r   r   update_modify   s   
zProject.update_modifyT)alwaysc                 C   s   |  S )z&Convert the company name to title caser,   )r   vr   r   r   company_name_format   s   zProject.company_name_formatr8   c                 C   s   |d du r
t dt|d j}t|}|rO|d du r#|j|d< |d du r.|j|d< |d du r9|j|d< |d du rO|jdusI|jdkrKd	nd
|d< | 	|}|S )z(Set the parameter values for the projectr\   Nz'Company url is required for new projectr]   r`   ra   rc   rF   publicrb   )

ValueErrorr   urlr   get_company_infor]   r`   ra   stock_tickerr   )r   field_valuesr\   company_infor   r   r   set_parameter_values   s&   






zProject.set_parameter_valuesc                 C   sL   | r$t  }||j| }||j| }|r|d |d< |r$tdi |S dS )z'Check the DB for the project structure.ri   Nr   )r   rG   projectsproject_structurer[   )r?   rK   responseproject_structure_responser   r   r   check_project_in_db   s   zProject.check_project_in_dbc                 C   s   |    t }d}| jdur/t| jtr/| jdd | jD | j| j| j| j	d}|
|j|}| jdhd}|
|j|}||gS )zUpdate the project in the DBNc                 S   s   g | ]}|  qS r   )rw   )r   sr   r   r   
<listcomp>   s    z0Project.update_project_in_db.<locals>.<listcomp>)r?   ri   rm   ro   rp   rq   ri   )exclude)r~   r   ri   
isinstancer   r?   rm   ro   rp   rq   upload_to_dynamodbr   rw   r   )rJ   rK   r   r   project_infoproject_responser   r   r   update_project_in_db   s"   zProject.update_project_in_dbc                 C   r:   r;   r<   r=   r   r   r   r     s   zProject.build_extrac                 C   s&   |d |d vr|d  |d  |S )z7assign the company name as one of the company alt namesr]   r^   )appendr=   r   r   r   assign_company_name_as_alt_name	  s   z'Project.assign_company_name_as_alt_namec                 C   s   |D ]>}zt |j}t|}W q ty@   zt|}t|  W n t	y= } zt
d|| W Y d}~nd}~ww Y qw dS )z"Verify the targets for the projectz)Error creating company profile for %s: %sN)r   r   r   r   r   r
   asynciorunmain	Exceptionloggingerror)r   rj   targetr\   r   cpme2r   r   r   verify_target  s"   
zProject.verify_targetc                 C   sH   t |j}i }|  D ]\}}t|||kr|||< q|  |S )zUpdate the project)r[   r   r?   rw   itemsgetattrr   )r   projectproject_in_dbupdated_fieldsr   valuer   r   r   update_project#  s   zProject.update_projectc                 C   s"   | j pg }ddd |D }|S )Nz


c                 s   s8    | ]}d |j  dddd |jpg D  V  qdS )z# Section: z


c                 s   s&    | ]}d |j  d|j dV  qdS )z
## Slide: z
### Research: 
r   N)r*   r5   )r   slider   r   r   	<genexpr>6  s
    
z@Project.convert_project_to_markdown.<locals>.<genexpr>.<genexpr>N)r*   joinrY   )r   sectionr   r   r   r   4  s    

z6Project.convert_project_to_markdown.<locals>.<genexpr>)ri   r   )rJ   ri   markdown_stringr   r   r   convert_project_to_markdown2  s
   

	z#Project.convert_project_to_markdown)Fr"   )5rN   rO   rP   rQ   r   r?   r$   rR   r\   r]   r^   r   r_   r`   ra   rc   rd   re   rg   rh   ri   rX   rj   rk   rl   ry   rz   rm   r{   r|   r}   ro   rp   rq   rr   rw   rs   rT   rx   r~   r	   rU   r   r   r   rV   r   r   r   r   r   r   r   r   r   r   r   r[   k   sx   
 


r[   )rQ   r   r{   ru   r   ry   typingr   r   r   r+   r   pydantic.v1r   r   r   r	   (services.company_profile.company_profiler
   2services.company_profile.data_classes.company_infor   8services.ppt_generator.data_classes.presentation_outliner   utils.dynamo_dbr   utils.url_parserr   r   r    rX   r[   r   r   r   r   <module>   s$    /