<?php
/**
 * Migration: Add Paystack columns to subscriptions and plans tables
 * Run this script to update your database schema for Paystack integration
 */

require_once __DIR__ . '/../config/database.php';

echo "Adding Paystack columns to database...\n";

try {
    // Add Paystack columns to subscriptions table
    $sql = "
        ALTER TABLE subscriptions 
        ADD COLUMN IF NOT EXISTS payment_method ENUM('manual','paystack','stripe') DEFAULT 'manual' AFTER cancelled_at,
        ADD COLUMN IF NOT EXISTS paystack_reference VARCHAR(100) NULL AFTER payment_method,
        ADD COLUMN IF NOT EXISTS paystack_subscription_code VARCHAR(100) NULL AFTER paystack_reference,
        ADD COLUMN IF NOT EXISTS paystack_customer_code VARCHAR(100) NULL AFTER paystack_subscription_code
    ";
    
    db()->exec($sql);
    echo "Added Paystack columns to subscriptions table\n";

    // Add Paystack plan code column to plans table
    $sql = "
        ALTER TABLE plans 
        ADD COLUMN IF NOT EXISTS paystack_plan_code VARCHAR(100) NULL AFTER features
    ";
    
    db()->exec($sql);
    echo "Added paystack_plan_code column to plans table\n";

    echo "Migration completed successfully!\n";
    
} catch (Exception $e) {
    echo "Migration failed: " . $e->getMessage() . "\n";
    exit(1);
}
