"""
HIPPO Configuration - Backend Version
Contains app knowledge, symptoms database, and AI prompts

HOW TO EXPAND:
- Add new pages to APP_PAGES
- Add new symptoms to SYMPTOMS
- Add new diseases to DISEASES
- Add new doctor types to DOCTOR_TYPES
"""

# =============================================================================
# APP KNOWLEDGE - Hipograf Platform Information
# =============================================================================

APP_PAGES = {
    "dashboard": {
        "path": "/",
        "name": "Dashboard",
        "description": "The patient home page with a 3D body model, timeline view, and customizable medical widgets.",
        "features": [
            "View disease markers on an interactive 3D humanoid model",
            "Open disease details from the selected marker",
            "View your medical timeline",
            "Use widgets for recent abnormal lab values, medications, wearable data, history, and upcoming schedule"
        ]
    },
    "timeline": {
        "path": "/timeline",
        "name": "Timeline",
        "description": "A centralized page for medical events shown as a timeline, weekly agenda, monthly/yearly calendar, or event history.",
        "features": [
            "Filter appointments, lab tests, prescriptions, and vaccinations by event type",
            "Zoom the timeline from day-level detail to multi-month views",
            "Use keyboard shortcuts for accessible timeline navigation"
        ]
    },
    "plots": {
        "path": "/plots",
        "name": "Plots",
        "description": "An interactive plotting system for lab values, prescriptions, and linked wearable metrics over time.",
        "features": [
            "Create plots from searchable datasets and date ranges",
            "Use AI-powered search such as kidney functions in the last 4 months",
            "Combine, split, resize, style, normalize, export, and save plot presets"
        ]
    },
    "visits": {
        "path": "/visits",
        "name": "Hospital Visits",
        "description": "A list of hospital visits with hospital, department, doctor, visit date, diagnoses, notes, and linked prescriptions.",
        "features": [
            "Sort visits by date, hospital name, or doctor name",
            "Search by hospital, doctor, department, diagnosis, or prescription",
            "Filter to visits that include diagnoses"
        ]
    },
    "prescriptions": {
        "path": "/prescriptions",
        "name": "Prescriptions",
        "description": "Medication records with dosage, linked diagnosis, consumption period, active/expired status, and detailed prescription pages.",
        "features": [
            "Filter active or expired prescriptions",
            "Open details for generic and brand name, class, route, dosage, frequency, linked visit, and linked diagnosis",
            "Review usage instructions, safety precautions, side effects, and export CSV data"
        ]
    },
    "diseases": {
        "path": "/diagnoses",
        "name": "Diagnoses",
        "description": "A searchable and sortable list of patient diagnoses with dates, ICD codes, departments, physicians, severity, details, and linked prescriptions.",
        "features": [
            "Sort by date, ICD code, diagnosis name, department, or doctor",
            "Filter by date range and severity",
            "Open clinical details, doctor notes, related prescriptions, and export CSV data"
        ]
    },
    "tests": {
        "path": "/tests",
        "name": "Lab Tests",
        "description": "Chronological lab test results, mostly blood work, with expandable subtests, reference ranges, and upload/edit support.",
        "features": [
            "Filter by date range, test/subtest search, and normal or out-of-reference status",
            "Open subtests on the timeline or plot page",
            "Upload lab tests manually or scan a PDF before reviewing extracted results"
        ]
    },
    "images": {
        "path": "/images",
        "name": "Imaging",
        "description": "Radiological images shown in grid or card view with image name, hospital, date, detail view, download, and upload support.",
        "features": [
            "Search by image name or hospital name",
            "Open images for closer inspection",
            "Upload scans with name, hospital, date, and image file"
        ]
    },
    "vaccinations": {
        "path": "/vaccinations",
        "name": "Vaccinations",
        "description": "Vaccination records in reverse chronological order.",
        "features": [
            "View vaccine name, date, and administering hospital",
            "Search by vaccine or hospital name",
            "Add vaccination records manually"
        ]
    },
    "devices": {
        "path": "/devices",
        "name": "Wearable Devices",
        "description": "Connected wearable and phone health data, synced through the mobile companion app.",
        "features": [
            "View connected device type, name, and last sync time",
            "Disconnect linked devices",
            "Review up to 30 days of heart rate, steps, calories, respiration, and related metrics"
        ]
    },
    "settings": {
        "path": "/settings",
        "name": "Settings",
        "description": "Account and data management for authenticated users.",
        "features": [
            "Update username, display name, email, and password",
            "Delete graph presets or uploaded tests",
            "Delete the account and associated data"
        ]
    },
    "practitioner": {
        "path": "/patients",
        "name": "Practitioner Pages",
        "description": "Practitioner-only views for linked patients, patient details, schedules, appointments, and patient-context analysis.",
        "features": [
            "List linked patients from the practitioner dashboard or patients page",
            "Open patient details with personal and medical overview information",
            "Enter a selected patient's data view with a persistent patient indicator"
        ]
    }
}

# =============================================================================
# DOCTOR TYPES
# =============================================================================

DOCTOR_TYPES = {
    "gp": {"name": "General Practitioner", "description": "First point of contact for general health concerns"},
    "cardio": {"name": "Cardiologist", "description": "Heart and blood vessel conditions"},
    "neuro": {"name": "Neurologist", "description": "Brain and nervous system conditions"},
    "gastro": {"name": "Gastroenterologist", "description": "Digestive system conditions"},
    "pulmo": {"name": "Pulmonologist", "description": "Lung and respiratory conditions"},
    "derm": {"name": "Dermatologist", "description": "Skin conditions"},
    "ortho": {"name": "Orthopedist", "description": "Bone, joint, and muscle conditions"},
    "ent": {"name": "ENT Specialist", "description": "Ear, nose, and throat conditions"},
    "uro": {"name": "Urologist", "description": "Urinary tract and kidney conditions"},
    "endo": {"name": "Endocrinologist", "description": "Hormone and metabolism conditions"},
    "psych": {"name": "Psychiatrist", "description": "Mental health conditions"},
    "opht": {"name": "Ophthalmologist", "description": "Eye conditions"},
    "rheum": {"name": "Rheumatologist", "description": "Rheumatic and autoimmune conditions"},
    "aller": {"name": "Allergist", "description": "Allergy and immune conditions"},
    "emergency": {"name": "Emergency Care", "description": "Urgent or life-threatening symptoms"}
}

# =============================================================================
# SYMPTOMS DATABASE
# =============================================================================

SYMPTOMS = [
    {"id": "headache", "name_tr": "Headache", "body_part": "head"},
    {"id": "migraine", "name_tr": "Migraine", "body_part": "head"},
    {"id": "dizziness", "name_tr": "Dizziness", "body_part": "head"},
    {"id": "fever", "name_tr": "Fever", "body_part": "general"},
    {"id": "fatigue", "name_tr": "Fatigue", "body_part": "general"},
    {"id": "cough", "name_tr": "Cough", "body_part": "chest"},
    {"id": "sore_throat", "name_tr": "Sore throat", "body_part": "throat"},
    {"id": "runny_nose", "name_tr": "Runny nose", "body_part": "nose"},
    {"id": "chest_pain", "name_tr": "Chest pain", "body_part": "chest"},
    {"id": "shortness_breath", "name_tr": "Shortness of breath", "body_part": "chest"},
    {"id": "stomach_pain", "name_tr": "Stomach pain", "body_part": "abdomen"},
    {"id": "nausea", "name_tr": "Nausea", "body_part": "abdomen"},
    {"id": "back_pain", "name_tr": "Back pain", "body_part": "back"},
    {"id": "joint_pain", "name_tr": "Joint pain", "body_part": "joints"},
    {"id": "rash", "name_tr": "Rash", "body_part": "skin"},
    {"id": "anxiety", "name_tr": "Anxiety", "body_part": "mental"},
    {"id": "insomnia", "name_tr": "Insomnia", "body_part": "mental"},
]

# =============================================================================
# DISEASES DATABASE
# =============================================================================

DISEASES = [
    {
        "id": "common_cold",
        "name_tr": "Common cold",
        "symptoms": ["runny_nose", "sore_throat", "cough", "fatigue"],
        "doctor_type": "gp",
        "urgency": "routine"
    },
    {
        "id": "flu",
        "name_tr": "Flu",
        "symptoms": ["fever", "cough", "fatigue", "headache"],
        "doctor_type": "gp",
        "urgency": "soon"
    },
    {
        "id": "migraine_disease",
        "name_tr": "Migraine",
        "symptoms": ["migraine", "nausea", "dizziness"],
        "doctor_type": "neuro",
        "urgency": "routine"
    },
    {
        "id": "gastritis",
        "name_tr": "Gastritis",
        "symptoms": ["stomach_pain", "nausea"],
        "doctor_type": "gastro",
        "urgency": "routine"
    },
    {
        "id": "heart_attack",
        "name_tr": "Heart attack",
        "symptoms": ["chest_pain", "shortness_breath", "nausea", "dizziness"],
        "doctor_type": "emergency",
        "urgency": "urgent"
    },
    {
        "id": "anxiety_disorder",
        "name_tr": "Anxiety disorder",
        "symptoms": ["anxiety", "insomnia", "fatigue"],
        "doctor_type": "psych",
        "urgency": "routine"
    }
]

# =============================================================================
# HIPPO AI CONFIGURATION
# =============================================================================

HIPPO_CONFIG = {
    "name": "HIPPO",
    "model": "llama-3.3-70b-versatile",
    "max_tokens": 512,
    "temperature": 0.7,

    "greeting": """Hi! I'm HIPPO, your Hipograf health assistant.

How can I help?

- Learn how to use Hipograf
- Get help with pages and features
- Ask for general symptom guidance""",

    "system_prompt": """You are HIPPO, the AI assistant for the Hipograf health platform.

WHAT HIPOGRAF IS:
Hipograf helps patients and medical practitioners visualize, manage, and review health information.
Patients can inspect their own medical data. Practitioners can review linked patients and, when needed, view the app through a selected patient's data context.

PAGES AND FEATURES:
{pages_info}

YOUR TASKS:
1. Help users understand Hipograf pages and workflows.
2. Give concise, step-by-step guidance for using the application.
3. Provide general symptom guidance when asked, including possible directions and what type of clinician may be appropriate.
4. Answer in English by default. Be warm, clear, and practical.

MEDICAL SAFETY RULES:
- Never present a definitive diagnosis.
- Always remind users that medical guidance does not replace a medical professional.
- For emergency symptoms such as chest pain, severe shortness of breath, stroke symptoms, fainting, or severe allergic reactions, tell the user to seek emergency care immediately.
- Keep answers short and direct unless the user asks for more detail.

IMPORTANT: Always state that medical advice from HIPPO is informational and cannot replace a doctor or licensed clinician."""
}

def get_pages_info():
    """Generate pages info string for system prompt"""
    info = []
    for key, page in APP_PAGES.items():
        features = ", ".join(page["features"][:2])
        info.append(f"- {page['name']} ({page['path']}): {page['description']} Features: {features}")
    return "\n".join(info)

def get_system_prompt():
    """Get the full system prompt with pages info"""
    pages_info = get_pages_info()
    return HIPPO_CONFIG["system_prompt"].format(pages_info=pages_info)
