"""
HEAD OR TAIL — central deployment configuration.
Edit these values; no other file needs changing to re-tune the economics.
"""

# ---------------- NETWORK ----------------
WS_PORT   = 9876          # WebSocket (game stream + cashier actions)
HTTP_PORT = 3002          # HTTP (pages + role APIs)

# ---------------- DATABASE (PostgreSQL on the VPS) ----------------
# Format: postgresql://USER:PASSWORD@HOST:PORT/DBNAME
# For a local Postgres on the same Contabo box, HOST is 127.0.0.1.
DB_DSN = "postgresql://hot_user:HotGame2026@127.0.0.1:5432/headortail"
DB_POOL_MIN = 2
DB_POOL_MAX = 10

# ---------------- GAME TIMING ----------------
NUM_COINS         = 6
BETTING_TIME      = 120    # seconds the betting window stays open
BET_LOCK_SECONDS  = 10     # last N seconds of the window: no new bets / no cancels
COIN_SPIN_SECONDS = 3      # spin time per coin (sequential reveal)
COIN_SHOW_SECONDS = 2      # how long each coin's result shows before next coin
WINNER_HOLD_SECS  = 5      # pause on results before next round
INTRO_COUNTDOWN   = 6      # short intro countdown between rounds

# ---------------- ECONOMICS (the dial) ----------------
# Of every 100 staked in a round:
#   PAYOUT_RATE  -> max returned to players (wins + near-miss + cashback + refunds)
#   HOUSE_RATE   -> house profit
#   JACKPOT_RATE -> fed into the jackpot pot
# These three MUST sum to 1.0.
PAYOUT_RATE  = 0.85       # 85% payout ceiling
HOUSE_RATE   = 0.10       # 10% house profit
JACKPOT_RATE = 0.05       # 5% jackpot

# House selection bias: among the SAFE outcomes (payout <= ceiling),
#   with probability HOUSE_BIAS pick the lowest-payout outcome (max house),
#   otherwise pick a random safe outcome (keeps results unpredictable).
# 1.0 = always minimise payout (most predictable), 0.0 = pure random among safe.
HOUSE_BIAS = 0.65

# ---------------- PAYOUT TIERS (exact-match multipliers) ----------------
BASE_MULTIPLIERS = {1: 1.9, 2: 3.7, 3: 7.5, 4: 15.0, 5: 30.0, 6: 60.0}

# Live multiplier damping by liability (0 = no damping, 0.7 = strong damping).
LIABILITY_DAMP = 0.7

# ---------------- CASHBACK / NEAR-MISS ----------------
NEAR_MISS_MULT      = 2.0     # 5- or 6-coin ticket missing by exactly one coin -> 2x stake
NEAR_MISS_SIZES     = (5, 6)  # which ticket sizes are eligible for near-miss
CASHBACK_MIN_TICKETS = 5      # >= this many tickets in one round, one player, clean sweep
CASHBACK_RATE       = 0.10    # 10% of aggregate stake of the qualifying group
CASHBACK_ROLLOVER   = 1.0     # 1x wagering rollover on the Fund credit

# ---------------- JACKPOT AWARD ----------------
# Jackpot pays ONLY from the accumulated pot, never from a round's reserve.
# Trigger: a winning 6-coin exact-sequence ticket on a "perfect" board
# (all six coins the same face). Tunable / can be disabled.
JACKPOT_ENABLED = True

# ---------------- IDENTITY ----------------
HOUSE_CODE = "HOT2025"     # barcode prefix
SHOP_NAME  = "HEAD OR TAIL"

# ---------------- TESTING ----------------
# When True, forces the first player's first bet to win every round.
# MUST be False for any real-money operation (it breaks the margin guarantee).
TEST_MODE = False

# ---------------- BOOTSTRAP DEFAULT ADMIN ----------------
# Created on first run if no admin exists. CHANGE the password after first login.
DEFAULT_ADMIN_USER = "admin"
DEFAULT_ADMIN_PASS = "admin"
DEFAULT_ADMIN_BALANCE = 1000000

# Sanity check
assert abs(PAYOUT_RATE + HOUSE_RATE + JACKPOT_RATE - 1.0) < 1e-9, \
    "PAYOUT_RATE + HOUSE_RATE + JACKPOT_RATE must equal 1.0"
