"""
License server config — shared between server, keygen, and client validator.
"""
from __future__ import annotations

import os
from pathlib import Path

# Server identity
PRODUCT_ID = "gold_autotrade"
PRODUCT_NAME = "Gold AutoTrade"
LICENSE_VERSION = 1

# Secret for HMAC signing (set via env var in production)
SIGNING_SECRET = os.environ.get("GAT_LICENSE_SECRET", "change-me-in-production")

# License tiers
TIERS = {
    "trial": {"max_days": 14, "max_machines": 1, "features": ["basic"]},
    "pro": {"max_days": 365, "max_machines": 2, "features": ["basic", "ai_signals", "auto_trade"]},
    "enterprise": {"max_days": 365, "max_machines": 10, "features": ["basic", "ai_signals", "auto_trade", "multi_tenant", "api_access"]},
}

# License key format: GAT-XXXX-XXXX-XXXX-XXXX (uppercase alphanum, 4 groups of 4)
KEY_PREFIX = "GAT"
KEY_GROUP_LENGTH = 4
KEY_GROUPS = 4

# Server paths
DATA_DIR = Path(__file__).resolve().parent / "data"
DB_PATH = DATA_DIR / "licenses.db"

# Client-side paths
def _default_license_dir() -> Path:
    """Cross-platform license storage directory."""
    if os.name == "nt":
        base = os.environ.get("APPDATA", os.path.expanduser("~"))
    elif os.sys.platform == "darwin":
        base = os.path.expanduser("~/Library/Application Support")
    else:
        base = os.environ.get("XDG_DATA_HOME", os.path.expanduser("~/.local/share"))
    return Path(base) / "GoldAutoTrade" / "license"

CLIENT_LICENSE_DIR = _default_license_dir()
CLIENT_LICENSE_FILE = CLIENT_LICENSE_DIR / "license.json"
CLIENT_PUBLIC_KEY_FILE = CLIENT_LICENSE_DIR / "public_key.pem"
