
    &Ci\                     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	|j                  d
      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  
company_idoffer_letter)questionsystem_prompt
max_tokensr   featurezDFailed to generate offer letter - AI service returned empty responsezError:zAI service error: T)r   r   z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
   sR   9	eON( 1%))%4::<"))%01 $8>9R8SSab M 11.AK  ??66$+)--l;& 7 L  <#5#5#72#=$c  &&x0$1,@    , 2 2 4 
  	 :3q6(C 	s5   +C# ,C# AC# 7C# C# #	D,D<DDc                    |j                  dd      j                         xs d}|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    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 packagecurrency_typeUSDzS
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
Currency: 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 z\
4. Clearly state the job title, department (if not "Not specified"), salary with currency ( a  ), 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
11. ALWAYS mention the salary with currency type (e.g., "50,000 USD" or "10,000 AED")

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