from datetime import datetime


# Get current date in a readable format
def get_current_date():
    return datetime.now().strftime("%B %d, %Y")


query_writer_instructions = """You will receive a product name and a target country or region.

Your task is to generate diverse, sophisticated web search queries covering multiple aspects of international market intelligence.

The goal is to help an automated agent explore:

1. Competitive Intelligence
- Major competing brands, sales channels, popular e-commerce platforms, pricing strategies, promotion tactics.

2. Market Signals and Demand
- Keyword popularity, consumer search behavior, e-commerce growth trends, user preferences, seasonal shifts.

3. Entry Barriers and Risks
- Regulatory hurdles, economic volatility, dominant competitors, distribution monopolies, geopolitical instability.

4. Market Gaps and Opportunities
- Underserved segments, unmet customer needs, price voids, platform white space, trend divergence.


Instructions:
- Generate corresponding 4 search queries to comprehensively cover the research topic.
- Each query should focus on one specific aspect of the original question.
- Don't produce more than {number_queries} queries.
- Queries should be diverse, if the topic is broad, generate more than 1 query.
- Don't generate multiple similar queries, 1 is enough.
- Query should ensure that the most current information is gathered. The current date is {current_date}.

Format: 
- Format your response as a JSON object with ALL two of these exact keys:
   - "rationale": Brief explanation of why these queries are relevant
   - "query": A list of search queries

Example:

Topic: What revenue grew more last year — Apple stock or the number of people buying an iPhone
```json
{{
    "rationale": "To determine which grew more — Apple stock value or iPhone user base — we need to retrieve annual growth data from Apple's financial reports, stock performance over the year, and global iPhone unit sales or active users. The queries aim to isolate each component's growth for a fair year-over-year comparison.",
    "query": [
        "Apple stock price increase percentage 2024",
        "Apple annual report 2024 iPhone unit sales",
        "Apple iPhone user growth 2024",
        "Apple revenue breakdown by product 2024",
        "iPhone market penetration or user base change 2023 vs 2024"
    ]
}}
```

Context: {research_topic}"""


web_searcher_instructions = """Conduct targeted Google Searches to gather the most recent, credible information on "{research_topic}" and synthesize it into a verifiable text artifact.

Instructions:
- Query should ensure that the most current information is gathered. The current date is {current_date}.
- Conduct multiple, diverse searches to gather comprehensive information.
- Consolidate key findings while meticulously tracking the source(s) for each specific piece of information.
- The output should be a well-written summary or report based on your search findings. 
- Only include the information found in the search results, don't make up any information.

Research Topic:
{research_topic}
"""

reflection_instructions = """You are an expert research assistant analyzing summaries about "{research_topic}".

Instructions:
- Identify knowledge gaps or areas that need deeper exploration and generate a follow-up query. (1 or multiple).
- If provided summaries are sufficient to answer the user's question, don't generate a follow-up query.
- If there is a knowledge gap, generate a follow-up query that would help expand your understanding.
- Focus on technical details, implementation specifics, or emerging trends that weren't fully covered.

Requirements:
- Ensure the follow-up query is self-contained and includes necessary context for web search.

Output Format:
- Format your response as a JSON object with these exact keys:
   - "is_sufficient": true or false
   - "knowledge_gap": Describe what information is missing or needs clarification
   - "follow_up_queries": Write a specific question to address this gap

Example:
```json
{{
    "is_sufficient": true, // or false
    "knowledge_gap": "The summary lacks information about performance metrics and benchmarks", // "" if is_sufficient is true
    "follow_up_queries": ["What are typical performance benchmarks and metrics used to evaluate [specific technology]?"] // [] if is_sufficient is true
}}
```

Reflect carefully on the Summaries to identify knowledge gaps and produce a follow-up query. Then, produce your output following this JSON format:

Summaries:
{summaries}
"""

answer_instructions = """You are generating a high-quality international market report tailored for **Chinese export companies**.

Instructions:
- The current date is {current_date}.
- Your task is to synthesize the following summaries into a clear, actionable market intelligence report.
- The report should help Chinese exporters understand the market and plan their entry/expansion strategy.

Your output must include:

1. **Executive Summary**  
   - Briefly summarize the current market status for the product in the target country or region.

2. **Market Insights**  
   - Highlight key findings from the research: macroeconomic trends, trade patterns, consumer preferences, competitors, e-commerce dynamics, and regulatory conditions.

3. **Strategic Recommendations for Chinese Exporters**  
   - Provide concrete suggestions in the following areas:
     - **Optimal product combinations**: Which product types, variants, or bundles are more likely to succeed?
     - **Positioning recommendations**: Value, premium, eco-friendly, smart-tech, etc.
     - **Pricing strategies**: Competitive pricing bands, opportunities for premium pricing, or price gaps.
     - **Preferred sales channels**: Offline distribution, e-commerce platforms (e.g., Shopee, Amazon), or cross-border B2B/B2C.
     - **Bundling or upsell tactics**: Suggestions for bundling with complementary products or services.

4. **Citations**  
   - Include references for every important insight or data point using markdown links, e.g. [Reuters](https://...).

Your tone should be informative, business-oriented, and suitable for use in a decision-support tool for exporters.

Translate the report into Chinese. The output should be in Chinese, no English should be included.

User Context:
- {research_topic}

Summaries:
{summaries}"""
