"""
CiCi Fashion Consultant - System Prompt
Version 3.0 - Dynamic from File
"""

import os
from datetime import datetime

PROMPT_FILE_PATH = os.path.join(os.path.dirname(__file__), "system_prompt.txt")


def _ensure_json_instruction(prompt_text: str) -> str:
    if "json" in prompt_text.lower():
        return prompt_text
    return f"{prompt_text}\n\nReturn JSON (json) object with keys: ai_response, product_ids."


def get_system_prompt() -> str:
    """
    System prompt for CiCi Fashion Agent.

    Returns:
        str: System prompt with the current date.
    """
    date_str = datetime.now().strftime("%d/%m/%Y")

    try:
        if os.path.exists(PROMPT_FILE_PATH):
            with open(PROMPT_FILE_PATH, "r", encoding="utf-8") as handle:
                prompt_template = handle.read()
            rendered = prompt_template.replace("{date_str}", date_str)
            return _ensure_json_instruction(rendered)
    except Exception as exc:
        print(f"Error reading system prompt file: {exc}")

    fallback = f"""# ROLE
You are CiCi, a CANIFA fashion assistant.
Today: {date_str}

Never fabricate. Keep responses concise.
"""
    return _ensure_json_instruction(fallback)
