# ===== TariffTradeAgent =====
class TariffTradeAgent:
    def __init__(self, client, deployment_id):
        self.client = client
        self.deployment_id = deployment_id

    def analyze_document(self, text):
        prompt = """You are a senior tariff and international trade policy analyst assisting a research team working for the CEO of Macy's.  
Carefully identify all significant tariff, trade, and related government policy topics in the text 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 1-sentence summary describing its operational or strategic impact on Macy's retail business.  
- A relevance score from 1 (minor) to 10 (critical).  
- Specific examples of how this issue may influence US retail, consumer behavior, procurement, supply chain logistics, or merchandising strategy.

Format your response as one topic per line in this format:  
- Topic Name: Summary [Relevance Score]

Example lines:  
- 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 text for all relevant tariff and trade topics. Text:
"""
        response = self.client.chat.completions.create(
            model=self.deployment_id,
            messages=[
                {"role": "system", "content": "Tariff and trade policy analyst for Macy's CEO"},
                {"role": "user", "content": prompt + "\n\n" + text}
            ],
            temperature=0
        )
        return self._parse_topics(response.choices[0].message.content.strip())

    def _parse_topics(self, text):
        topics = []
        pattern = r'^- (.*?): (.*?) \[(\d+)\]$'
        for line in text.split('\n'):
            line = line.strip()
            match = re.match(pattern, line)
            if match:
                topics.append({
                    'name': match.group(1).strip(),
                    'summary': match.group(2).strip(),
                    'score': int(match.group(3).strip())
                })
        return topics

    def stream_generate_detail(self, text, topic):
        prompt = f"""You are preparing a detailed briefing for Macy's CEO on the tariff and trade policy topic '{topic}', based on the provided document.

Provide:
1. A clear overview of the topic.
2. Key insights and any relevant direct excerpts from the document.
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.

Document:
{text}

Topic: {topic}

Please deliver the response as structured markdown suitable for executive briefing."""
        messages = [
            {"role": "system", "content": "Senior tariff analyst briefing to Macy's CEO"},
            {"role": "user", "content": prompt}
        ]
        response = self.client.chat.completions.create(
            model=self.deployment_id,
            messages=messages,
            temperature=0,
            stream=True,
        )
        return response

    def generate_consolidated_summary_from_topics(self, processed_files):
        # --- NEW APPROACH: Send full file contents for consolidated summary ---
        files_block = ""
        for filename, filedata in processed_files.items():
            content_excerpt = filedata['text'] 
            files_block += f"=== Document: {filename} ===\n{content_excerpt}\n\n"

        prompt = f"""You are a senior tariff and trade policy analyst preparing a brief report for Macy's executive team.

Based on the content of the following documents, please:

1. Identify and describe all the impactful tariff, trade, and related government policy topics affecting tariff, profitable tariff, or non-affecting tariff, trade, that relate to  Macy's business operations, including these all example: supply chain, procurement, retail sales, and technology.
2. For each topic:
   - Provide a concise summary.
   - Include relevant examples, numerical data, or timelines from the documents.
   - Explain operational and strategic impacts on Macy's retail business, including positive, negative, or neutral effects.
   - Provide 3-5 actionable strategic recommendations for Macy's leadership.
3. Format the response using markdown with clear headings.
4. Avoid jargon and focus on actionable insights.

Documents:
{files_block}

Deliver a detailed consolidated tariff and trade policy report.
"""

        response = self.client.chat.completions.create(
            model=self.deployment_id,
            messages=[
                {"role": "system", "content": "Senior analyst creating consolidated tariff and trade report"},
                {"role": "user", "content": prompt}
            ],
            temperature=0
        )
        return response.choices[0].message.content.strip()


# ===== SustainabilityAgent =====
class SustainabilityAgent:
    def __init__(self, client, deployment_id):
        self.client = client
        self.deployment_id = deployment_id

    def analyze_document(self, text):
        prompt = """You are a senior analyst specializing in Sustainability, ESG (Environmental, Social, Governance), and corporate responsibility topics.  
Identify all significant ESG and sustainability-related topics in the text that could influence Macy's corporate responsibility, brand reputation, ethical supply chain management, or stakeholder relations.

For each topic, provide:  
- A concise and clear topic name (e.g., "Carbon Footprint Reduction", "Ethical Sourcing Initiatives").  
- A brief 1-sentence summary describing the topic's relevance or impact on Macy's operations or reputation.  
- A relevance score from 1 (minor) to 10 (critical).

Format the output as one topic per line in this format:  
- Topic Name: Summary [Relevance Score]

Example lines:  
- Renewable Energy Adoption: Macy's increasing solar panel use in stores nationwide [7]  
- Labor Rights Compliance: Strengthening oversight on supplier labor conditions [9]

Analyze the following text for relevant ESG and sustainability topics. Text:
"""
        response = self.client.chat.completions.create(
            model=self.deployment_id,
            messages=[
                {"role": "system", "content": "Sustainability and ESG analyst for Macy's management"},
                {"role": "user", "content": prompt + "\n\n" + text}
            ],
            temperature=0
        )
        return self._parse_topics(response.choices[0].message.content.strip())

    def _parse_topics(self, text):
        topics = []
        pattern = r'^- (.*?): (.*?) \[(\d+)\]$'
        for line in text.split('\n'):
            line = line.strip()
            match = re.match(pattern, line)
            if match:
                topics.append({
                    'name': match.group(1).strip(),
                    'summary': match.group(2).strip(),
                    'score': int(match.group(3).strip())
                })
        return topics

    def stream_generate_detail(self, text, topic):
        prompt = f"""You are drafting a detailed briefing for Macy's CEO on the sustainability topic '{topic}', based on the provided document.

Provide:
1. An overview of the topic.
2. Key insights and relevant excerpts.
3. Current figures, goals, or timelines.
4. Potential impact on Macy's brand, CSR, supply chain ethics, and stakeholder relations.
5. 3-5 strategic recommendations to enhance Macy's sustainability performance.

Document:
{text}

Topic: {topic}

Deliver as structured markdown for executive review."""
        messages = [
            {"role": "system", "content": "Senior ESG analyst preparing briefing for Macy's CEO"},
            {"role": "user", "content": prompt}
        ]
        response = self.client.chat.completions.create(
            model=self.deployment_id,
            messages=messages,
            temperature=0,
            stream=True,
        )
        return response

    def generate_consolidated_summary_from_topics(self, processed_files):
        # --- NEW APPROACH: Send full file contents for consolidated summary ---

        files_block = ""
        for filename, filedata in processed_files.items():
            content_excerpt = filedata['text'] 
            files_block += f"=== Document: {filename} ===\n{content_excerpt}\n\n"

        prompt = f"""You are a senior ESG analyst preparing a consolidated sustainability and ESG report for Macy's executive team.

Based on the content of the following documents, please:

1. Identify and describe all the critical, profitable, or non-affecting ESG and sustainability topics affecting Macy's corporate responsibility, brand reputation, ethical supply chain management, or stakeholder relations.
2. For each topic:
   - Provide a concise summary.
   - Include relevant numerical targets, timelines, or examples from the documents.
   - Explain operational and strategic impacts—positive, negative, or neutral—specifically tailored to Macy's retail, CSR, and stakeholder engagement.
   - Provide 3-5 actionable strategic recommendations to enhance Macy's sustainability performance.
3. Use markdown formatting with clear headings.
4. Avoid jargon and focus on practical operational impacts and strategy insights.

Documents:
{files_block}

Deliver a detailed consolidated sustainability and ESG report.
"""

        response = self.client.chat.completions.create(
            model=self.deployment_id,
            messages=[
                {"role": "system", "content": "Senior analyst creating consolidated sustainability report"},
                {"role": "user", "content": prompt}
            ],
            temperature=0
        )
        return response.choices[0].message.content.strip()

the files we are uploading is from different company and we like to give the upladte to Macy's excutive team about the things from these files so make it accordingly the prompts that we are from macy uplaoding the file transcript of different companies need to get knowldge about all the things in them so make my prompts accroding to them 

give me full code