<?php

/**
 * Migration 0052 — directory messages carry their sender listing
 *
 * Contact reframe (Sergei 2026-07-24): the public profile form is gone;
 * messaging is member-to-member, sent from the token-authenticated portal.
 * sender_listing_id records WHICH member sent a message — the identity
 * spine for referral tracking later. NULL = legacy public-form era rows.
 *
 * @since 2.1.2501
 */

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

return [
    'description' => 'directory_messages.sender_listing_id (member-to-member identity)',

    'up' => [],

    'php' => function () {
        $t = \Instinctor\Core\DB::prefix() . 'instinctor_directory_messages';
        $hasCol = (int) \Instinctor\Core\DB::get_var(\Instinctor\Core\DB::prepare(
            'SELECT COUNT(*) FROM information_schema.COLUMNS
             WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = %s AND COLUMN_NAME = %s',
            $t, 'sender_listing_id'
        )) > 0;
        if (!$hasCol) {
            \Instinctor\Core\DB::query("ALTER TABLE {$t} ADD COLUMN sender_listing_id bigint(20) unsigned NULL DEFAULT NULL");
            \Instinctor\Core\DB::query("ALTER TABLE {$t} ADD KEY sender_listing_id (sender_listing_id)");
        }
    },
];
