from prometheus_client import Counter

cohorts = tuple("AB")

Cohort = Counter(
    "donate_cohort_count",
    "Cohort assigned for A/B testing",
    ["cohort"]
)
# initialize the counter so we have output on startup
for cohort in cohorts:
    Cohort.labels(cohort).inc(0)
    Cohort.labels(cohort).inc(0)

RateLimiter = Counter(
    "donate_rate_limiter",
    "Rate limiting triggered",
    ["type", "method", "cohort"]
)
# initialize the counter so we have output on startup
for cohort in cohorts:
    RateLimiter.labels("ip", "GET", cohort).inc(0)

# Count of individual validation errors, not "invalid forms"; each of these validation errors
# represents an issue the front end should have caught but didn't.
DonationProcessingError = Counter(
    "donate_form_submission_error_count",
    "Number of errors encountered when processing donation form",
    ["type", "cohort"]
)

DonationTransactionCount = Counter(
    "donate_transaction_count",
    "Number of donations validated and sent to CiviCRM",
    ["type", "status", "cohort"]
)
# possible values here are `single`, `recurring`, and `Completed`, and `Failed`
for cohort in cohorts:
    DonationTransactionCount.labels("single", "Completed", cohort).inc(0)

StripePaymentIntentCount = Counter(
    "donate_stripe_payment_intent_count",
    "Number of payment intent sent to Stripe",
    ["status", "cohort"],
)
for cohort in cohorts:
    StripePaymentIntentCount.labels("success", cohort).inc(0)

WebhookValidation = Counter(
    "donate_webhook_message_count",
    "Number of webhook messages received",
    ["status", "vendor", "cohort"]
)
# possible values are "failure", "success" and (currently) "stripe" and "paypal"
for cohort in cohorts:
    WebhookValidation.labels("success", "stripe", cohort).inc(0)

PaypalIPNValidation = Counter(
    "donate_paypal_ipn_message_count",
    "Number of legacy Paypal IPN messages received",
    ["status", "cohort"]
)
# possible values are "failure" and "success"
for cohort in cohorts:
    PaypalIPNValidation.labels("success", cohort).inc(0)

# Successful webhook messages do not always imply successful transactions, and
# not all transactions are important to report about to CiviCRM; this counter
# therefore tracks all successfully-reported-upon transactions which passed
# initial form validation, but which eventually were rejected by the payment
# processor - often indicating cards with a high fraud warning level, which at
# volume probably indicates card testing.
DonationVendorTransactionCount = Counter(
    "donate_vendor_transaction_count",
    "Number of transactions processed by vendor",
    ["status", "type", "vendor", "cohort"]
)
# possible values are "failure" and "success", "single" and "recurring",
# and (currently) "stripe" and "paypal"
for cohort in cohorts:
    DonationVendorTransactionCount.labels("success", "single", "stripe", cohort).inc(0)
