from agents.base_agent import BaseAgent

class TariffTradeAgent(BaseAgent):
    prompt_sys = "Tariff and trade policy analyst for Macy's CEO works for only provided documents"
    
     # Universal formatting enforcement line
    formatting_directive = """Please follow these formatting guidelines:
1. **No Combined Elements**: Always space-separate numbers/words/units (3.3 billion not 3.3billion)
2. **Time Formatting**: Q4 2024 (never Q42024 or 4th quarter)
3. **Number Rules**: 
   - 3.3B → 3.3 billion
   - 150.2M → 150.2 million
   - 0.33 → keep exact decimal
4. **Text Integrity**: 
   - "net income" never "netincome"
   - "year-over-year" never "YOY" or "yearoveryear"
5. **Style Prohibition**: Do not make any word in Italic or any other format always make it in one format
6. **Bad Example**: 3.3billioninQ42024,withanadjustednetincomeof, 106million,withadjustedearningsperdilutedshareat0.95 → REJECTED
7. **ALWAYS Required Format**: 3.3 billion in Q4 2024, with an adjusted net income of → ACCEPTED

APPLY THESE RULES TO ALL NUMERICAL MENTIONS AND SENTENCE STRUCTURES."""
    
    prompt_analyze = """
You are a senior tariff and international trade policy analyst assisting a research team working for the CEO of Macy's.  
You have received a transcript/document from another company.  

Carefully identify all significant tariff, trade, and related government policy topics and detailed briefing in the text of all files that could affect Macy's business operations, including supply chain, procurement, retail sales, and technology.

For each topic, provide:  
- A clear and concise topic name (e.g., "Vietnam Production Impact", "US-China Tariffs").  
- A brief describing in 200 words including its operational or strategic impact on Macy's retail business, considering the external company's context also include A clear overview of the topic, Key insights and any relevant direct excerpts from the document, Important figures, dates, or timelines if available, Detailed analysis on how this topic could impact Macy's retail operations, supply chain, procurement, and consumer behavior.  
- A relevance score from 1 (minor) to 10 (critical).  
* For every topic, ALWAYS provide verbatim source excerpts under the heading "Source Truth" as follows:
        - For each document where the topic appears, extract the exact, unmodified sentence(s) or paragraph(s) from the original document. 
        - Format each excerpt as: **Source Truth:** "Exact text from the document..." (Document Name)
        - If a topic is present in multiple documents, include a separate "Source Truth" excerpt for each document.
        - Do NOT paraphrase, summarize, or alter the original text in any way. The excerpt must match the source exactly, including all formatting, punctuation, and special characters.
        - If the LLM cannot find an exact match in the document, do NOT fabricate or modify the excerpt—only include what is present in the source.

Format your response as one topic per line in the format from all files:  
- Topic Name: Summary [Relevance Score]

Example:  
- Vietnam Factory Shutdown: Supply chain delays expected due to production halt in Vietnam [9]  
- Tariff Changes on Apparel: Increased costs on imports from China may raise prices [8]

Analyze the following external company document for all relevant tariff and trade topics. Text:""" + formatting_directive 

    prompt_summary = """
You are a senior tariff and trade analyst preparing a consolidated tariff and trade policy report for Macy's executive team from all document provided.

You have reviewed tariff and trade topics extracted from multiple external company documents. These topics include their names, summaries, and relevance scores. Based on their content, please:

1. **OverView**: Identify and describe from all documents all their impactful tariff, trade, and related government policy topics that could affect Macy's business operations, including supply chain, procurement, retail sales, and technology.
2. For each topic:
   * Provide a concise summary from combining all the documents.
   * Include relevant examples, numerical data, or timelines from the documents also provide from which document it is taken.
   * Explain operational and strategic impacts—positive, negative, or neutral—specifically tailored to Macy's retail business.
   * Provide 3-5 actionable strategic recommendations for Macy's leadership.
   * For every topic, ALWAYS provide each verbatim source excerpts under the heading "Ground Truth" as follows:
        - For each document where the topic appears, extract the exact, unmodified sentence(s) or paragraph(s) from the original document. 
        - Format each excerpt as: **Ground Truth:** "Exact text from the document..." (Document Name)
        - If a topic is present in multiple documents, include a separate "Ground Truth" excerpt for each document with proper line breaks.
        - Do NOT paraphrase, summarize, or alter the original text in any way. The excerpt must match the source exactly, including all formatting, punctuation, and special characters.
        - If the LLM cannot find an exact match in the document, do NOT fabricate or modify the excerpt—only include what is present in the source.
  
3. Format in clear markdown with sections in black text with proper headings:
    * Executive Summary
    * Key Themes
    * Strategic Recommendations
    * Risk Assessment
4. Avoid jargon and focus on practical operational impacts and strategy insights.

Format your response in markdown with clear headings for each topic.

Use the following Documents Analysis Data to combine similar topics from different documents and provide a comprehensive summary:
{topics_block}

Deliver a detailed, synthesized, and actionable consolidated tariff and trade policy report for Macy's.""" + formatting_directive 

    prompt_detail = """
You are preparing a detailed briefing for Macy's CEO on the tariff and trade policy topic '{topic}', based on the provided external company document.

Provide:
1. A clear overview of the topic.
2. Allways Provide Key insights and relevant excerpts.- For this topic, extract and present the relevant text verbatim from the source document that contains the key information. Ensure that the extracted text is placed in a separate paragraph and is not embedded within any other paragraph. Additionally, include the name of the source document alongside the quoted text for audit and traceability purposes.
3. Important figures, dates, or timelines if available.
4. Detailed analysis on how this topic could impact Macy's retail operations, supply chain, procurement, and consumer behavior.
5. 3-5 actionable strategic recommendations for Macy's leadership.
6 For every topic, ALWAYS provide verbatim source excerpts under the heading "Ground Truth" as follows:
        - For each document where the topic appears, extract the exact, unmodified sentence(s) or paragraph(s) from the original document. 
        - Format each excerpt as: **Ground Truth:** "Exact text from the document..." (Document Name)
        - If a topic is present in multiple documents, include a separate "Source Truth" excerpt for each document.
        - Do NOT paraphrase, summarize, or alter the original text in any way. The excerpt must match the source exactly, including all formatting, punctuation, and special characters.
        - If the LLM cannot find an exact match in the document, do NOT fabricate or modify the excerpt—only include what is present in the source.


Document:
{text}

Topic: {topic}

Please deliver the response as structured with proper paragraphs and bold topics which suitable for executive briefing.""" + formatting_directive 

    def analyze_document(self, text, custom_prompt=None):
        prompt_analyze = custom_prompt if custom_prompt else self.prompt_analyze
        return super().analyze_document(self.prompt_sys, prompt_analyze, text)

    def generate_consolidated_summary_from_topics(self, processed_files, custom_prompt=None):
        prompt_summary = custom_prompt if custom_prompt else self.prompt_summary
        return super().generate_consolidated_summary_from_topics(self.prompt_sys, prompt_summary, processed_files)

    def generate_topic_detail(self, text, topic, custom_prompt=None):
        prompt_detail = custom_prompt if custom_prompt else self.prompt_detail
        return super().generate_topic_detail(self.prompt_sys, prompt_detail, text, topic)

change this according to below only

US Politics / Tariffs
Prompt: Summarize how the company spoke to tariff impact. Lead with any country or regional sourcing exposure, if applicable. Then also provide any quantitative financial impact, if applicable. Finally, provide the mitigation actions it has either already implemented or is planning to implement, including changes to pricing. If no detail is provided, say “N/A”.

The output should be a summary of the commentary, in 100 words or less. The summary should be in the third person (name of the company, management, the company)
We do not need the recommendation to Macy’s management for the specific commentary modules – we just want the bulleted summary of the commentary for each.