from dotenv import load_dotenv
import os
import logging

# Configure logging
logging.basicConfig(
    level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
logger = logging.getLogger(__name__)

load_dotenv()

# Discord
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN", "")

# Endpoints
CHAT_ENDPOINT = os.getenv("CHAT_ENDPOINT", "")
COMPLETION_ENDPOINT = os.getenv("COMPLETION_ENDPOINT", "")
IMAGE_GEN_ENDPOINT = os.getenv("IMAGE_GEN_ENDPOINT", "")
IMAGE_EDIT_ENDPOINT = os.getenv("IMAGE_EDIT_ENDPOINT", "")
EMBEDDING_ENDPOINT = os.getenv("EMBEDDING_ENDPOINT", "")
MAX_COMPLETION_TOKENS = int(os.getenv("MAX_COMPLETION_TOKENS", "1000"))

# API Keys
CHAT_ENDPOINT_KEY = os.getenv("CHAT_ENDPOINT_KEY", "placeholder")
COMPLETION_ENDPOINT_KEY = os.getenv("COMPLETION_ENDPOINT_KEY", "placeholder")
IMAGE_GEN_ENDPOINT_KEY = os.getenv("IMAGE_GEN_ENDPOINT_KEY", "placeholder")
IMAGE_EDIT_ENDPOINT_KEY = os.getenv("IMAGE_EDIT_ENDPOINT_KEY", "placeholder")
EMBEDDING_ENDPOINT_KEY = os.getenv("EMBEDDING_ENDPOINT_KEY", "placeholder")

# Models
CHAT_MODEL = os.getenv("CHAT_MODEL", "")
COMPLETION_MODEL = os.getenv("COMPLETION_MODEL", "")
IMAGE_GEN_MODEL = os.getenv("IMAGE_GEN_MODEL", "")
IMAGE_EDIT_MODEL = os.getenv("IMAGE_EDIT_MODEL", "")
EMBEDDING_MODEL = os.getenv("EMBEDDING_MODEL", "")

# Database and embeddings
DB_PATH = os.getenv("DB_PATH", "chat_history.db")
EMBEDDING_DIMENSION = 2048
MAX_HISTORY_MESSAGES = int(os.getenv("MAX_HISTORY_MESSAGES", "1000"))
SIMILARITY_THRESHOLD = float(os.getenv("SIMILARITY_THRESHOLD", "0.7"))
TOP_K_RESULTS = int(os.getenv("TOP_K_RESULTS", "5"))

# Check token
if not DISCORD_TOKEN:
    raise Exception("DISCORD_TOKEN required.")

# Check endpoints
if not CHAT_ENDPOINT:
    raise Exception("CHAT_ENDPOINT required.")

if not COMPLETION_ENDPOINT:
    raise Exception("COMPLETION_ENDPOINT required.")

if not IMAGE_GEN_ENDPOINT:
    raise Exception("IMAGE_GEN_ENDPOINT required.")

if not IMAGE_EDIT_ENDPOINT:
    raise Exception("IMAGE_EDIT_ENDPOINT required.")

if not EMBEDDING_ENDPOINT:
    raise Exception("EMBEDDING_ENDPOINT required.")

# Check models
if not CHAT_MODEL:
    raise Exception("CHAT_MODEL required.")

if not COMPLETION_MODEL:
    raise Exception("COMPLETION_MODEL required.")

if not IMAGE_GEN_MODEL:
    raise Exception("IMAGE_GEN_MODEL required.")

if not IMAGE_EDIT_MODEL:
    raise Exception("IMAGE_EDIT_MODEL required.")

if not EMBEDDING_MODEL:
    raise Exception("EMBEDDING_MODEL required.")

logger.info(f"CHAT_ENDPOINT set to {CHAT_ENDPOINT}")
logger.info(f"COMPLETION_ENDPOINT set to {COMPLETION_ENDPOINT}")
logger.info(f"IMAGE_GEN_ENDPOINT set to {IMAGE_GEN_ENDPOINT}")
logger.info(f"IMAGE_EDIT_ENDPOINT set to {IMAGE_EDIT_ENDPOINT}")
logger.info(f"EMBEDDING_ENDPOINT set to {EMBEDDING_ENDPOINT}")
