import os
import platform

# Check if running under pytest
TESTING = "PYTEST_CURRENT_TEST" in os.environ

# Base Directory
BASE_DIR = os.path.dirname(os.path.abspath(__file__))

# Debugging
DEBUG = os.getenv("RADIONICA_DEBUG", "True").lower() == "true"

# Slicer Settings
# If True, triggers synchronous slicing upon file upload (slower upload, exact metrics on UI)
SYNC_SLICING_ON_UPLOAD = os.getenv("SYNC_SLICING", "True").lower() == "true"
IS_WINDOWS = platform.system() == "Windows"

if IS_WINDOWS:
    # Default Windows path
    SLICER_PATH = os.getenv("SLICER_PATH", r"C:\Program Files\Prusa3D\PrusaSlicer\prusa-slicer-console.exe")
else:
    # Default Linux path (binary name if in PATH, or absolute path)
    SLICER_PATH = os.getenv("SLICER_PATH", "prusa-slicer") 

# Profile configuration (can be changed per machine)
SLICER_CONFIG = os.getenv("SLICER_CONFIG", os.path.join(BASE_DIR, "printer_profile.ini"))

# Order settings
UPLOAD_DIR = os.getenv("UPLOAD_DIR", os.path.join(BASE_DIR, "uploads"))
PREVIEW_DIR = os.path.join(UPLOAD_DIR, "previews")
CHAT_UPLOADS_DIR = os.path.join(UPLOAD_DIR, "chats")
for d in [UPLOAD_DIR, PREVIEW_DIR, CHAT_UPLOADS_DIR]:
    if not os.path.exists(d):
        os.makedirs(d)

# Payment Config
ZIRO_RACUN = os.getenv("ZIRO_RACUN", "510-1234567890123-45")
COMPANY_NAME = "RADIONICA 3D"
COMPANY_PIB = os.getenv("COMPANY_PIB", "01234567")
COMPANY_CITY = "Podgorica"
COMPANY_ADDRESS = "Cetinjski Put, Podgorica, Montenegro"
PDV_RATE = 21 # In percent
DEFAULT_PRINTER_HOUR_PRICE = 2.0 # Default price per hour of printing

# EFI Fiskalizacija
EFI_ENABLED = os.getenv("EFI_ENABLED", "False").lower() == "true"
EFI_CERT_PATH = os.getenv("EFI_CERT_PATH", os.path.join(BASE_DIR, "cert.p12"))
EFI_CERT_PASS = os.getenv("EFI_CERT_PASS", "changeit")
EFI_ENU_CODE = os.getenv("EFI_ENU_CODE", "xx123yy456") 
EFI_BUS_UNIT = os.getenv("EFI_BUS_UNIT", "br123")      
EFI_OPERATOR = os.getenv("EFI_OPERATOR", "op123")      
EFI_STAGING = os.getenv("EFI_STAGING", "True").lower() == "true"
GOOGLE_CLIENT_ID = os.getenv("GOOGLE_CLIENT_ID", "254513580225-j893ad8nd2f2celd2thn1l42miqm9e7s.apps.googleusercontent.com")

# SMTP Configuration (Local MTA)
SMTP_HOST = os.getenv("SMTP_HOST", "localhost")
SMTP_PORT = int(os.getenv("SMTP_PORT", "25"))
SMTP_USER = os.getenv("SMTP_USER", "")
SMTP_PASS = os.getenv("SMTP_PASS", "")
SMTP_FROM = os.getenv("SMTP_FROM", "hello@radionica3d.me")
# Frontend URL for links in emails
FRONTEND_URL = os.getenv("FRONTEND_URL", "https://radionica3d.me")

# Telegram Notifications
TELEGRAM_CHAT_ID = os.getenv("CHAT_ID")

# Redis Configuration
REDIS_HOST = os.getenv("REDIS_HOST", "localhost")
REDIS_PORT = int(os.getenv("REDIS_PORT", "6379"))
