
    ڵ1i                     4    d dl mZ d dlmZmZ  G d d      Zy)    )	AIService)DictAnyc                   P    e Zd Zd Zdeeef   deeef   fdZdeeef   defdZy)OfferLetterServicec                 "    t               | _        y)z3Initialize the offer letter service with AI serviceN)r   
ai_service)selfs    A/var/www/html/drjob-dev/drjob-ai/services/offer_letter_service.py__init__zOfferLetterService.__init__   s    #+    candidate_datareturnc                    	 g d}g }|D ]4  }|j                  |d      j                         r$|j                  |       6 |rdddj                  |       ddS d}| j	                  |      }| j
                  j                  ||d	
      }|r|j                         dk(  rdddS |j                  d      rdd| dS d|j                         dS # t        $ r}ddt        |       dcY d}~S d}~ww xY w)a<  
        Generate an offer letter using AI based on provided candidate and job information
        
        Args:
            candidate_data: Dictionary containing candidate and job information
            
        Returns:
            Dict containing success status and either offer_letter or error message
        )candidate_name	job_titlecompany_name
start_datesalary FzRequired fields missing: z, z are mandatory)successerrora  
You are a professional HR assistant specialized in creating formal offer letters. 
Generate a professional, warm, and comprehensive offer letter using ONLY the provided information.
Do NOT include any placeholder text like [Your Company Letterhead], [Your Contact Information], [Date], [Address], etc.
Start directly with the greeting and use only the actual data provided.
The letter should be clean, professional, and contain only real information.
i  )questionsystem_prompt
max_tokenszDFailed to generate offer letter - AI service returned empty responsezError:zAI service error: T)r   offer_letterzError generating offer letter: N)
getstripappendjoin_build_user_promptr	   ai_response
startswith	Exceptionstr)	r
   r   required_fieldsmissing_fieldsfieldr   user_promptr   es	            r   generate_offer_letterz(OfferLetterService.generate_offer_letter
   sA   7	eON( 1%))%4::<"))%01 $8>9R8SSab M 11.AK  ??66$+ 7 L  <#5#5#72#=$c  &&x0$1,@    , 2 2 4 
  	 :3q6(C 	s5   +C ,C A
C &C ?C 	C6C1+C61C6c                 J   |j                  dd      j                         xs d}|j                  dd      j                         xs d}|j                  dd      j                         xs d}d|d	    d
|d    d| d|d    d|d    d|d    d| d| d|d	    d|d    d}|S )z
        Build the user prompt for AI offer letter generation
        
        Args:
            candidate_data: Dictionary containing candidate and job information
            
        Returns:
            Formatted user prompt string
        
departmentr   zNot specifiedemployment_typez	Full-timebenefitsz!Standard company benefits packagezS
Generate a professional offer letter with the following details:

Candidate Name: r   z
Job Title: r   z
Department: z
Company Name: r   z
Start Date: r   z	
Salary: r   z
Employment Type: z
Benefits: z6

CRITICAL INSTRUCTIONS:
1. Start directly with "Dear z," - NO letterhead, addresses, or placeholder text
2. DO NOT include [Your Company Letterhead], [Date], [Your Contact Information], [Address], [Acceptance Deadline], or ANY text in brackets []
3. Express pleasure in offering the position from a  
4. Clearly state the job title, department (if not "Not specified"), salary, and start date
5. Include employment type and benefits information
6. DO NOT use "Warm regards", "Sincerely", [Your Name], [Your Title], or any signature blocks
7. End ONLY with "Please review the offer and confirm your decision below." - NO additional text after this
8. Use ONLY the actual data provided - NO placeholder text, NO brackets [], NO [Date], NO [Acceptance Deadline Date]
9. Be professional and direct
10. Generate only the clean offer letter content - NO signature, NO closing formalities

Please generate the offer letter using ONLY the real data provided.
)r   r   )r
   r   r-   r.   r/   r)   s         r   r!   z%OfferLetterService._build_user_promptM   s    $''b9??AT_
(,,->CIIKZ{!%%j"5;;=dAd   012 3;'( )L n-. /L)* +			!" #!" #*  --=>? @33A.3Q2R 
S6 r   N)	__name__
__module____qualname__r   r   r%   r   r+   r!    r   r   r   r      sJ    &ADcN AtCQTH~ AF*c3h *C *r   r   N)services.ai_servicer   typingr   r   r   r3   r   r   <module>r6      s    ) r rr   