import os

# Required parameters
# API Settings
BACKEND_HOST = os.getenv("BACKEND_HOST", "https://api-dev.gptbase.ai")
MASTERKEY = os.getenv("MASTERKEY", "master")
FASTAPI_URL = os.getenv('FASTAPI_URL', 'http://127.0.0.1:8001')

# LLM Token Settings
MAX_CONTEXT_TOKENS = int(os.getenv("MAX_CONTEXT_TOKENS", 200000))
MAX_OUTPUT_TOKENS = int(os.getenv("MAX_OUTPUT_TOKENS", 8000))

# Optional parameters
# Summarization Settings
SUMMARIZATION_MAX_TOKENS = int(MAX_CONTEXT_TOKENS/2)
SUMMARIZATION_TOKENS_TO_KEEP = int(SUMMARIZATION_MAX_TOKENS/3)
DEFAULT_TRIM_TOKEN_LIMIT = SUMMARIZATION_MAX_TOKENS - SUMMARIZATION_TOKENS_TO_KEEP + 5000

# Agent Cache Settings
TOOL_CACHE_MAX_SIZE = int(os.getenv("TOOL_CACHE_MAX_SIZE", 20))
TOOL_CACHE_TTL = int(os.getenv("TOOL_CACHE_TTL", 180))
TOOL_CACHE_AUTO_RENEW = os.getenv("TOOL_CACHE_AUTO_RENEW", "true") == "true"

# Project Settings
PROJECT_DATA_DIR = os.getenv("PROJECT_DATA_DIR", "./projects/data")
SKILLS_DIR = os.getenv("SKILLS_DIR", "./skills")
PROJECT_NAME = os.getenv("PROJECT_NAME", "support")

# Tokenizer Settings
TOKENIZERS_PARALLELISM = os.getenv("TOKENIZERS_PARALLELISM", "true")

# Embedding Model Settings
SENTENCE_TRANSFORMER_MODEL = os.getenv("SENTENCE_TRANSFORMER_MODEL", "TaylorAI/gte-tiny")

# Tool Output Length Control Settings
TOOL_OUTPUT_MAX_LENGTH = SUMMARIZATION_MAX_TOKENS
TOOL_OUTPUT_TRUNCATION_STRATEGY = os.getenv("TOOL_OUTPUT_TRUNCATION_STRATEGY", "smart")



# WebDAV Authentication
WEBDAV_USERNAME = os.getenv("WEBDAV_USERNAME", "admin")
WEBDAV_PASSWORD = os.getenv("WEBDAV_PASSWORD", "MmL85TjjxZC97hk9rsYfhQ")

# MCP Tool Timeout Settings
MCP_HTTP_TIMEOUT = int(os.getenv("MCP_HTTP_TIMEOUT", 60))  # HTTP request timeout (seconds)
MCP_SSE_READ_TIMEOUT = int(os.getenv("MCP_SSE_READ_TIMEOUT", 300))  # SSE read timeout (seconds)

# ============================================================
# PostgreSQL Checkpoint Configuration
# ============================================================

# PostgreSQL connection string
# Format: postgresql://user:password@host:port/database
#CHECKPOINT_DB_URL = os.getenv("CHECKPOINT_DB_URL", "postgresql://postgres:AeEGDB0b7Z5GK0E2tblt@dev-circleo-pg.celp3nik7oaq.ap-northeast-1.rds.amazonaws.com:5432/gptbase")
CHECKPOINT_DB_URL = os.getenv("CHECKPOINT_DB_URL", "postgresql://moshui:@localhost:5432/moshui")

# Connection pool size
# Maximum number of simultaneous connections
CHECKPOINT_POOL_SIZE = int(os.getenv("CHECKPOINT_POOL_SIZE", "20"))
MEM0_POOL_SIZE = int(os.getenv("MEM0_POOL_SIZE", "50"))

# Checkpoint auto-cleanup configuration
# Whether to enable automatic cleanup of old sessions
CHECKPOINT_CLEANUP_ENABLED = os.getenv("CHECKPOINT_CLEANUP_ENABLED", "true") == "true"

# Number of days after which inactive threads are cleaned up
CHECKPOINT_CLEANUP_INACTIVE_DAYS = int(os.getenv("CHECKPOINT_CLEANUP_INACTIVE_DAYS", "3"))

# Cleanup interval (hours)
# How many hours between cleanup runs
CHECKPOINT_CLEANUP_INTERVAL_HOURS = int(os.getenv("CHECKPOINT_CLEANUP_INTERVAL_HOURS", "24"))


# ============================================================
# Mem0 long-term memory configuration
# ============================================================

# Mem0 feature toggle (global)
MEM0_ENABLED = os.getenv("MEM0_ENABLED", "true") == "true"

# Semantic search configuration
# Number of memories to recall
MEM0_SEMANTIC_SEARCH_TOP_K = int(os.getenv("MEM0_SEMANTIC_SEARCH_TOP_K", "20"))

# ============================================================
# Schedule job configuration
# ============================================================

# Whether to enable the scheduled job runner
SCHEDULE_ENABLED = os.getenv("SCHEDULE_ENABLED", "true") == "true"

# Scheduler scan interval (seconds)
SCHEDULE_SCAN_INTERVAL = int(os.getenv("SCHEDULE_SCAN_INTERVAL", "60"))

# Maximum number of concurrent scheduled jobs
SCHEDULE_MAX_CONCURRENT = int(os.getenv("SCHEDULE_MAX_CONCURRENT", "5"))


# ============================================================
# Daytona sandbox configuration
# ============================================================

DAYTONA_API_KEY = os.getenv("DAYTONA_API_KEY", "dtn_ccf86acd5b13a3069a8369d12d8cb26a9a184d07451374dfc325955fc2d8331c")
DAYTONA_SERVER_URL = os.getenv("DAYTONA_SERVER_URL", "https://daytona-dev.gbase.ai/api")
# DAYTONA_API_KEY = os.getenv("DAYTONA_API_KEY", "dtn_696a914ff54e45bb97132c32fba10995a4cab8ebef0cd8dea18129d447f805a3")
# DAYTONA_SERVER_URL = os.getenv("DAYTONA_SERVER_URL", "https://app.daytona.io/api")
DAYTONA_ENABLED = os.getenv("DAYTONA_ENABLED", "false") == "true"
os.environ["OPENAI_API_KEY"] = "your_api_key"
