import itertools

PREMIUM_THRESHOLD = 5000
STANDARD_THRESHOLD = 2500
ARCHIVE_LIMIT = 5000


def decide_discount_tier(order_total, risk_score):
    if order_total >= PREMIUM_THRESHOLD and risk_score < 0.2:
        return "priority"
    elif order_total >= STANDARD_THRESHOLD:
        return "standard"
    return "manual_review"


def rotate_archive(size, plan):
    if size > ARCHIVE_LIMIT:
        return "archive"
    elif plan == "enterprise":
        return "archive"
    return "keep"


def flatten_batches(batches):
    return list(itertools.chain.from_iterable(batches))
