<?php

/**
 * Migration 0034 — Class packs (punch cards) for the Instructor vertical.
 *
 * A pack is a prepaid balance of class credits a member buys (e.g. "10 classes").
 * Booking a class deducts one credit. Memberships (active subscriptions) grant
 * access without touching packs; packs are the pay-as-you-go alternative for
 * non-members. One row per purchased pack so credits + expiry are auditable.
 */

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

return [
    'description' => 'Class packs (prepaid class-credit balances)',

    'up' => [
        "CREATE TABLE IF NOT EXISTS {prefix}instinctor_class_packs (
            id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
            customer_id bigint(20) unsigned NOT NULL,
            total int NOT NULL DEFAULT 0,
            remaining int NOT NULL DEFAULT 0,
            order_id bigint(20) unsigned DEFAULT NULL,
            expires_at datetime DEFAULT NULL,
            meta longtext,
            created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
            updated_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            PRIMARY KEY (id),
            KEY customer_id (customer_id),
            KEY remaining (remaining)
        ) {charset}",
    ],

    'down' => [
        "DROP TABLE IF EXISTS {prefix}instinctor_class_packs",
    ],
];
