import os
from dotenv import load_dotenv

# Load .env file
load_dotenv()

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

# Database settings
DB_HOST = os.getenv("DB_HOST", "localhost")
DB_PORT = int(os.getenv("DB_PORT", "5432"))
DB_NAME = os.getenv("DB_NAME", "gamble_db")
DB_USER = os.getenv("DB_USER", "postgres")
DB_PASSWORD = os.getenv("DB_PASSWORD", "")

# SQLite Fallback
# If no PostgreSQL token/host is specified or we want to run locally, use SQLite file.
USE_SQLITE = not os.getenv("DB_PASSWORD") and not os.getenv("DB_HOST")
SQLITE_PATH = "gamble_bot.db"

# Channel IDs (Convert to integers or None)
def get_int_env(name, default=None):
    val = os.getenv(name)
    if val and val.isdigit():
        return int(val)
    return default

ADMIN_LOG_CHANNEL_ID = get_int_env("ADMIN_LOG_CHANNEL_ID")
ADMIN_APPROVAL_CHANNEL_ID = get_int_env("ADMIN_APPROVAL_CHANNEL_ID")
PUBLIC_LOG_CHANNEL_ID = get_int_env("PUBLIC_LOG_CHANNEL_ID")
BOT_STATUS_CHANNEL_ID = get_int_env("BOT_STATUS_CHANNEL_ID")

# Limits & Security Configuration
WITHDRAW_APPROVAL_LIMIT = float(os.getenv("WITHDRAW_APPROVAL_LIMIT", "500000000.0")) # 500m auto approval threshold
ALT_ACCOUNT_AGE_DAYS = int(os.getenv("ALT_ACCOUNT_AGE_DAYS", "30"))
COMMAND_COOLDOWN_SECONDS = float(os.getenv("COMMAND_COOLDOWN_SECONDS", "3.0"))
GAMES_ENABLED = True # Killswitch flag for emergency game freeze

# Game Configuration
COINFLIP_WIN_CHANCE = 0.50  # 50% chance
BLACKJACK_DECK_COUNT = 6    # Number of decks for blackjack
SLOTS_EMOJIS = ["🍒", "🍋", "🍊", "🍇", "🔔", "💎", "7️⃣"]
SLOTS_PAYOUTS = {
    "7️⃣": 10.0,
    "💎": 7.0,
    "🔔": 5.0,
    "🍇": 3.0,
    "🍊": 2.5,
    "🍋": 2.0,
    "🍒": 1.5
}
