from .database import db


def load_active_slots() -> list[dict]:
    return db.fetch_all(
        """
        SELECT * FROM slots
        WHERE status = 'enabled'
        ORDER BY price_rise_pct DESC, priority ASC, id ASC
        """
    )


def validate_slot_amount(leverage: int, amount: float) -> tuple[bool, str]:
    caps = {1: 20000, 2: 20000, 3: 20000, 5: 10000, 10: 5000, 20: 0}
    max_allowed = caps.get(int(leverage), 0)
    if int(leverage) == 20:
        return False, "20X is disabled for Version 1."
    if amount <= 0:
        return False, "Amount must be greater than zero."
    if amount > max_allowed:
        return False, f"Maximum amount for {leverage}X is INR {max_allowed}."
    return True, "OK"

