<?php
/**
 * File Path: includes/migrations/class-mbs-migration-2-2.php
 *
 * MBS_Migration_2_2 — Sprint F-026 — contact_type column
 *
 * Add contact_type VARCHAR(20) column to mbs_arc_recipients (ADD COLUMN IF NOT EXISTS, idempotent).
 *
 * @package MyBookShowroom
 * @since   3.2.0
 */

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

/**
 * Class MBS_Migration_2_2
 *
 * Add contact_type VARCHAR(20) column to mbs_arc_recipients (ADD COLUMN IF NOT EXISTS, idempotent).
 *
 * @implements MBS_Migration
 */
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- DAO/migration: table names via $wpdb->prefix are trusted server-controlled values, not user input
// phpcs:disable PluginCheck.Security.DirectDB.UnescapedDBParameter -- same reason: $wpdb->prefix table names are safe; $where_sql is built from sanitized server-controlled inputs
class MBS_Migration_2_2 implements MBS_Migration { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- mbs_/MBS_ prefix is correct; scanner not configured with plugin prefix

	/**
	 * {@inheritdoc}
	 *
	 * @return string
	 */
	public function version(): string {
		return '2.2';
	}

	/**
	 * {@inheritdoc}
	 *
	 * Add contact_type VARCHAR(20) column to mbs_arc_recipients (ADD COLUMN IF NOT EXISTS, idempotent).
	 *
	 * @return void
	 */
	public function up(): void {
		global $wpdb;
		$table = $wpdb->prefix . 'mbs_arc_recipients';
		// phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange
		$wpdb->query( "ALTER TABLE `{$table}` ADD COLUMN IF NOT EXISTS `contact_type` VARCHAR(20) NULL DEFAULT NULL AFTER `contact_method`" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange -- DAO layer -- direct DB access is intentional per MBS architecture
	}
}
