"""
Configuration for SL CAT TOPUP Web Store
"""

import os

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
PARENT_DIR = os.path.dirname(BASE_DIR)

# Database
DATABASE_PATH = os.path.join(BASE_DIR, "topup_store.db")

# Uploads directory for slips
UPLOAD_FOLDER = os.path.join(BASE_DIR, "static", "uploads")
os.makedirs(UPLOAD_FOLDER, exist_ok=True)

# Path to shared HTG Session Cookies & Multi-Account Storage
HTG_SESSION_PATH = os.path.join(BASE_DIR, "htg_session.json")
if not os.path.exists(HTG_SESSION_PATH) and os.path.exists(os.path.join(PARENT_DIR, "htg_session.json")):
    HTG_SESSION_PATH = os.path.join(PARENT_DIR, "htg_session.json")

HTG_ACCOUNTS_PATH = os.path.join(BASE_DIR, "htg_accounts.json")
if not os.path.exists(HTG_ACCOUNTS_PATH) and os.path.exists(os.path.join(PARENT_DIR, "htg_accounts.json")):
    HTG_ACCOUNTS_PATH = os.path.join(PARENT_DIR, "htg_accounts.json")

# Admin Security
ADMIN_PIN = "7981"  # Simple admin passcode for dashboard
ADMIN_FF_ID = "2332538025"  # Admin's personal Free Fire UID (Crazy Owner)

# Web Server Settings
SERVER_HOST = "0.0.0.0"
SERVER_PORT = 5000

# Email IMAP Listener Settings (For receiving HelaPOS / Bank notification emails)
EMAIL_IMAP_SERVER = "imap.gmail.com"
EMAIL_IMAP_PORT = 993
EMAIL_USER = "your_email@gmail.com"
EMAIL_APP_PASSWORD = ""  # 16-character Google App Password
EMAIL_CHECK_INTERVAL = 3  # check every 3 seconds

# Base LankaQR Payload (Seylan / HelaPOS Base)
BASE_LANKAQR = (
    "00020101021126320028162880001628800006220001107052045411"
    "53031445802LK5912-Crazy Owner6010Kurunegala6105003006229052501026202565000000000000006304E280"
)

# Official Store Bank Accounts for Manual Bank Transfers (Randomized & User Selectable)
BANK_ACCOUNTS = [
    {
        "id": "combank",
        "name": "Commercial Bank of Ceylon",
        "short_name": "Commercial Bank",
        "account_number": "8027985799",
        "account_name": "MR I P U KARUNARATHNE",
        "branch": "141 - POLGAHAWELA BRANCH",
        "badge": "ePassbook Live",
        "color": "#3b82f6",
        "gradient": "linear-gradient(145deg, rgba(30, 58, 138, 0.35), rgba(15, 23, 42, 0.9))",
        "border": "#3b82f6",
        "app_hint": "Combank Digital / Q+ / Any Bank App",
    },
    {
        "id": "boc",
        "name": "Bank of Ceylon (BOC)",
        "short_name": "Bank of Ceylon",
        "account_number": "6692413",
        "account_name": "I P U KARUNARATHNE",
        "branch": "Pothuhera",
        "badge": "SmartPay Live",
        "color": "#eab308",
        "gradient": "linear-gradient(145deg, rgba(180, 83, 9, 0.35), rgba(15, 23, 42, 0.9))",
        "border": "#eab308",
        "app_hint": "BOC B App / SmartPay / Any Bank App",
    },
]

# Client Selling Prices (LKR)
# Any public customer can purchase at these prices
CLIENT_PRICES = {
    # Memberships
    "1": 350.0,               # Weekly Membership ➡️ Rs. 350
    "2": 1910.0,              # Monthly Membership ➡️ Rs. 1,910
    "3": 120.0,               # Weekly Lite Membership ➡️ Rs. 120
    # VIP Bundles
    "bundle_vip": 2300.0,      # VIP Bundle (1 Weekly + 1 Monthly) ➡️ Rs. 2,300
    "bundle_svip": 3455.0,     # SVIP Bundle (4 Weekly + 1 Monthly) ➡️ Rs. 3,455
    "bundle_vip_max": 2450.0,  # VIP Max Bundle (1W + 1M + 1WL) ➡️ Rs. 2,450
    "bundle_svip_max": 4000.0, # SVIP Max Bundle (4W + 1M + 4WL) ➡️ Rs. 4,000
    # Diamonds
    "6": 75.0,                # 25 Diamonds
    "7": 280.0,               # 100 Diamonds
    "8": 840.0,               # 310 Diamonds
    "9": 1400.0,              # 520 Diamonds
    "10": 2750.0,             # 1060 Diamonds
    "11": 5500.0,             # 2180 Diamonds
    "12": 13800.0,            # 5600 Diamonds
    "13": 27500.0,            # 11500 Diamonds
    # Level Up Pass (10% Discount Applied)
    "86": 81.0,               # level up pass 6 (Original: Rs. 90 ➡️ -10% = Rs. 81)
    "87": 175.5,              # level up pass 10 (Original: Rs. 195 ➡️ -10% = Rs. 175.50)
    "88": 175.5,              # level up pass 15 (Original: Rs. 195 ➡️ -10% = Rs. 175.50)
    "89": 175.5,              # level up pass 20 (Original: Rs. 195 ➡️ -10% = Rs. 175.50)
    "90": 175.5,              # level up pass 25 (Original: Rs. 195 ➡️ -10% = Rs. 175.50)
    "91": 279.0,              # level up pass 30 (Original: Rs. 310 ➡️ -10% = Rs. 279)
}

def get_product_price(product_id: str, default_price: float = 0.0) -> float:
    return CLIENT_PRICES.get(str(product_id), default_price)
