import json


def get_synthesis_prompt(
    project_name: str,
    project_description: str,
    market_result: str,
    financial_result: str,
    competitive_result: str,
    language: str,
) -> list:
    from app.ai.prompts.dynamic import get_dynamic_prompt
    override = get_dynamic_prompt(
        "synthesis", project_name, project_description, language,
        market_result=market_result,
        financial_result=financial_result,
        competitive_result=competitive_result,
    )
    if override:
        return override

    lang_instruction = "Respond entirely in Arabic." if language == "ar" else "Respond entirely in English."

    return [
        {
            "role": "system",
            "content": (
                "You are a senior strategic advisor and decision-maker. You receive analyses from three "
                "specialist analysts (Market, Financial, Competitive) and must synthesize them into a "
                "final comprehensive feasibility verdict. "
                "Weigh contradicting arguments carefully. Resolve conflicts between the three analyses. "
                f"{lang_instruction}\n\n"
                "Return your response as valid JSON with these keys:\n"
                "verdict: one of 'GO', 'NO-GO', 'CONDITIONAL',\n"
                "verdict_explanation: string,\n"
                "viability_score: {overall: number 0-100, market: number 0-100, financial: number 0-100, competitive: number 0-100, team_readiness: number 0-100, innovation: number 0-100},\n"
                "executive_summary: string (2-3 paragraphs),\n"
                "project_description: string,\n"
                "market_analysis_summary: string,\n"
                "tam_sam_som: {tam: string, sam: string, som: string, tam_value: string, sam_value: string, som_value: string},\n"
                "financial_analysis_summary: string,\n"
                "competitive_analysis_summary: string,\n"
                "swot: {strengths: [], weaknesses: [], opportunities: [], threats: []},\n"
                "pestel: {political: string, economic: string, social: string, "
                "technological: string, environmental: string, legal: string},\n"
                "porters_five_forces: {threat_new_entrants: string, bargaining_power_suppliers: string, "
                "bargaining_power_buyers: string, threat_substitutes: string, industry_rivalry: string},\n"
                "business_model_canvas: {key_partners: [], key_activities: [], key_resources: [], "
                "value_propositions: [], customer_relationships: [], channels: [], "
                "customer_segments: [], cost_structure: [], revenue_streams: []},\n"
                "lean_canvas: {problem: [], solution: [], unique_value: string, unfair_advantage: string, "
                "customer_segments: [], key_metrics: [], channels: [], cost_structure: [], revenue_streams: []},\n"
                "gtm_strategy: {phase1: string, phase2: string, phase3: string, pricing_strategy: string, "
                "distribution_channels: [], launch_tactics: []},\n"
                "mvp_definition: {core_features: [], nice_to_have: [], estimated_timeline: string, estimated_cost: string},\n"
                "target_audience: [{persona_name: string, description: string, needs: []}],\n"
                "marketing_strategy: {channels: [], branding: string, positioning: string, "
                "slogan_ideas: [], social_media_tips: []},\n"
                "financial_highlights: {estimated_startup_cost: string, monthly_costs: string, "
                "break_even: string, revenue_potential: string, roi_estimate: string, "
                "year1_revenue: string, year2_revenue: string, year3_revenue: string},\n"
                "risks_and_mitigations: [{risk: string, severity: string, mitigation: string}],\n"
                "recommendations: [],\n"
                "vrio: {resources: [{name: string, valuable: boolean, rare: boolean, inimitable: boolean, organized: boolean, competitive_advantage: string}]},\n"
                "startup_cost_breakdown: {items: [{item: string, cost: string, category: string}], total: string, notes: string},\n"
                "  IMPORTANT: startup_cost_breakdown items MUST include ALL of the following categories where applicable: "
                "rent/lease deposit, office/store furniture, equipment & devices (computers, printers, POS, etc.), "
                "renovation & interior design, licenses & permits, legal & registration fees, "
                "insurance, initial inventory/raw materials, branding & logo design, website/app development, "
                "initial marketing & advertising, recruitment costs, working capital reserve (3-6 months), "
                "utilities setup (electricity, internet, phone). Provide realistic cost estimates.\n"
                "monthly_operating_costs: {items: [{item: string, cost: string}], total: string},\n"
                "  IMPORTANT: monthly_operating_costs items MUST include: rent, salaries & wages, "
                "utilities (electricity, water, internet, phone), marketing & advertising, "
                "insurance, maintenance, accounting & legal, supplies, software subscriptions, "
                "transportation, miscellaneous. Provide realistic monthly estimates.\n"
                "staffing_plan: [{role: string, count: number, monthly_salary: string}],\n"
                "revenue_streams_detail: [{name: string, description: string, percentage: string}],\n"
                "industry_benchmarks: {industry: string, avg_margin: string, avg_growth: string, market_size: string, comparison_notes: string},\n"
                "usp: string,\n"
                "final_verdict: string (detailed final recommendation paragraph),\n"
                "confidence_score: number (0-100)"
            ),
        },
        {
            "role": "user",
            "content": (
                f"## Business Idea\nName: {project_name}\nDescription: {project_description}\n\n"
                f"## Market Logic Analysis\n{market_result}\n\n"
                f"## Financial Sustainability Analysis\n{financial_result}\n\n"
                f"## Competitive Durability Analysis\n{competitive_result}\n\n"
                "Based on the three analyses above, provide your final synthesis and verdict. "
                "Resolve any contradictions between the analyses. "
                "Be thorough and strategic in your assessment. "
                "Include TAM/SAM/SOM market sizing, Business Model Canvas, Lean Canvas, "
                "Go-to-Market strategy, MVP definition, viability scoring across 5 dimensions, "
                "VRIO analysis, revenue streams with percentages, industry benchmarks comparison, and USP.\n\n"
                "CRITICAL: For startup_cost_breakdown, provide a DETAILED itemized list covering ALL real-world costs: "
                "rent deposit, furniture, equipment (computers/devices/POS), renovation, licenses, legal fees, "
                "insurance, initial inventory, branding, website/app, initial marketing, recruitment, working capital reserve, utilities setup. "
                "Do NOT combine costs into generic categories like 'development' or 'infrastructure'. "
                "Each line item should be a specific, identifiable expense.\n"
                "Also provide monthly_operating_costs with ALL recurring monthly expenses (rent, salaries, utilities, marketing, etc.) "
                "and a staffing_plan with specific roles, headcount and salaries."
            ),
        },
    ]
