<IfModule mod_headers.c>
    Header always set Access-Control-Allow-Origin "*"
    Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS"
    Header always set Access-Control-Allow-Headers "Content-Type, X-App-Name"
</IfModule>

# Return 200 for all OPTIONS preflight requests immediately
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^ - [R=200,L]

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /api/

    RewriteRule ^v1/subscription/status/?$       v1/check_subscription.php  [L,QSA]
    RewriteRule ^v1/otp/request/?$               v1/send_otp.php            [L,QSA]
    RewriteRule ^v1/otp/verify/?$                v1/verify_otp.php          [L,QSA]
    RewriteRule ^v1/subscription/unsubscribe/?$  v1/unsubscribe.php         [L,QSA]
    RewriteRule ^v1/ussd/?$                      v1/ussd_send.php           [L,QSA]
    RewriteRule ^v1/ussd/receive/?$              v1/ussd_receive.php        [L,QSA]
</IfModule>

# Block direct access to sensitive files
<FilesMatch "^(app_credentials|app_auth)\.php$">
    Deny from all
</FilesMatch>
