<?php
/**
 * File Path: includes/migrations/class-mbs-migration-3-4.php
 *
 * MBS_Migration_3_4 -- Sprint POS-2 -- Add square_item_id to mbs_format_rows
 *
 * Adds an optional VARCHAR(100) column to store the Square catalog item ID
 * for each format row.  Used by the Square for WooCommerce integration so
 * the author can map each book edition to its Square catalog entry.
 *
 * dbDelta handles the ADD COLUMN idempotently; re-running on an already-
 * updated table is a no-op.
 *
 * @package MyBookShowroom
 * @since   3.4.0
 */

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

/**
 * Class MBS_Migration_3_4
 *
 * @implements MBS_Migration
 */
class MBS_Migration_3_4 implements MBS_Migration { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- mbs_/MBS_ prefix is correct; scanner not configured with plugin prefix

	public function version(): string {
		return '3.4';
	}

	public function up(): void {
		global $wpdb;
		$table          = $wpdb->prefix . 'mbs_format_rows';
		$charset_collate = $wpdb->get_charset_collate();

		// dbDelta only adds columns; it never drops or modifies existing ones.
		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
		dbDelta( "CREATE TABLE {$table} (
			id            BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
			square_item_id VARCHAR(100)   NULL DEFAULT NULL,
			PRIMARY KEY (id)
		) {$charset_collate};" );
	}
}
