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 strictly follow these formatting guidelines for all numerical mentions and sentence structures:
1. **No Combined Elements**: Always space-separate numbers, words, and units (e.g., "3.3 billion" not "3.3billion").
2. **Time Formatting**: Use formats like "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 italicize or alter text formatting; maintain a single plain format throughout.
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 = (
        "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”.\n\n"
        "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).\n\n"
        "For every topic, ALWAYS provide excerpts mentioned under the heading \"Ground Truth\" as follows:\n"
        "- For each document where the topic appears, extract the exact, unmodified sentence(s) or paragraph(s) from the original document.\n"
        "- Format each excerpt as: **Ground Truth:** \"Exact text from the document...\" (Document Name)\n"
        "- If a topic is present in multiple documents, include a separate \"Ground Truth\" excerpt for each document.\n"
        "- 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.\n"
        "- 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 document.\n\n"
        "Format the output as a concise summary without recommendations.\n\n"
        "Document 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 documents provided.\n\n"
        "Identify and describe all impactful tariff, trade, and related government policy topics across the documents provided that could affect Macy's business operations including supply chain, procurement, retail sales, and technology.\n\n"
        "For each topic:\n"
        "- Provide a concise summary by combining relevant information from the documents.\n"
        "- Include relevant financial impacts, examples, figures, or timelines.\n"
        "- Provide three to five actionable strategic recommendations based on the analysis.\n\n"
        "For every topic, ALWAYS provide each excerpt mentioned under the heading \"Ground Truth\" as follows:\n"
        "- For each document where the topic appears, extract the exact, unmodified sentence(s) or paragraph(s) from the original document.\n"
        "- Format each excerpt as: **Ground Truth:** \"Exact text from the document...\" (Document Name)\n"
        "- If a topic is in multiple documents, include separate excerpts for each document with proper line breaks.\n"
        "- Do NOT paraphrase or alter any text.\n"
        "- If no exact excerpts are found, do NOT fabricate or modify content.\n\n"
        "Format the report in clear markdown with sections:\n"
        "- Executive Summary\n"
        "- Key Themes\n"
        "- Strategic Recommendations\n"
        "- Risk Assessment\n\n"
        "STRICTLY enforce plain text formatting:\n"
        + 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.\n\n"
        "Provide:\n"
        "1. A clear overview of the topic.\n"
        "2. Key insights and relevant excerpts.\n"
        "3. Important figures, dates, or timelines if available.\n"
        "4. A detailed analysis on how this topic could impact Macy's retail operations, supply chain, procurement, and consumer behavior.\n"
        "5. Three to five actionable strategic recommendations for Macy's leadership.\n\n"
        "For every topic, ALWAYS provide verbatim source excerpts under the heading \"Ground Truth\" as follows:\n"
        "- For each document where the topic appears, extract the exact, unmodified sentence(s) or paragraph(s) from the original document.\n"
        "- Format each excerpt as: **Ground Truth:** \"Exact text from the document...\" (Document Name)\n"
        "- If a topic is present in multiple documents, include a separate excerpt for each.\n"
        "- Do NOT paraphrase, summarize, or alter the text.\n"
        "- If no exact excerpts exist, do NOT fabricate or modify content.\n\n"
        "Document:\n"
        "{text}\n\n"
        "Topic: {topic}\n\n"
        "Please provide a structured briefing with clear paragraphs and bold topics.\n"
        + 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)


make this prompt as below instruction

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.


also for analyze topic prompt need like 
You are a senior business analyst working directly for Macy's CEO. Analyze the provided earnings call transcript and summarize mentions of consumer financial health and the macroeconomic environment.
 
Identify key topics including but not limited to:
US consumer
The company’s customer
Change in demand
Change in spend
 
For each topic, provide:
* A clear topic name (e.g., "E-commerce Growth", "Supply Chain Digitization")
* Concise 100-word summary providing key numbers and operational impacts
* Strictly preserve original numerical and textual formatting: maintain exact decimals (0.33), required spacing between numbers/text (0.11 → '0.11'), and verbatim terminology without concatenation or rephrasing.
* For every topic, ALWAYS provide excerpts mentioned 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.
        - Do NOT paraphrase, summarize, or alter the original text in any way. The excerpt must match the document data 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 documents.
Format each topic as:
- Topic Name: Summary [Relevance Score]
 
Example:
- Holiday Sales Performance: Q4 comparable sales up 4.2% driven by 18% digital growth [8]
- Inventory Optimization: Implementing AI demand forecasting to reduce carrying costs by $150M [7]
Document Text:STRICTLY ENFORCE PLAIN TEXT FORMATTING:
2. **No Combined Elements**: Always space-separate numbers/words/units (3.3 billion not 3.3billion)
3. **Time Formatting**: Q4 2024 (never Q42024 or 4th quarter)
4. **Number Rules**: 
   - 3.3B → 3.3 billion
   - 150.2M → 150.2 million
   - 0.33 → keep exact decimal
5. **Text Integrity**: 
   - "net income" never "netincome"
   - "YOY " never "year-over-year" or "yearoveryear"
   - “vs.” never “versus” or “vs”
   - “$XB” never “$X billion”
   - “$XM” never “$X million”
6. **Style Prohibition**: Do not make any word in Italic or any other format always make it in one format
7. **Bad Example**: 3.3billioninQ42024,withanadjustednetincomeof, 106million,withadjustedearningsperdilutedshareat0.95 → REJECTED
8. **ALLWAYS 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.


but have only the 
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”.
in it