<?php
/**
 * Affiliate Coupon Helper
 *
 * Handles generating coupon IDs from discount percentages.
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

class STRP_SUB_Affiliate_Coupon_Helper {
    /**
     * Map a discount percentage to a Stripe coupon ID.
     *
     * @param  int         $percent Discount percentage (e.g. 20 = 20%).
     * @return string|null          Stripe coupon ID, or null when $percent <= 0.
     */
    public static function get_coupon_id_for_discount( $percent ) {
        $prefix = apply_filters( 'strp_sub_affiliate_coupon_prefix', 'PARTNER' );
        $percent = max( 0, min( 100, (int) $percent ) );
        $prefix  = preg_replace( '/[^A-Z0-9_-]/i', '', $prefix );
        return ( $percent > 0 ) ? $prefix . $percent : null;
    }
}
