<?php

return static function (PDO $pdo): void {
    installRequireCoreTables($pdo, ['recipients']);

    $tableSql = <<<'SQL'
CREATE TABLE IF NOT EXISTS `member_password_resets` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `recipient_id` int(11) NOT NULL,
  `email` varchar(255) NOT NULL,
  `reset_token` varchar(100) NOT NULL,
  `expires_at` datetime NOT NULL,
  `used` tinyint(1) NOT NULL DEFAULT 0,
  `used_at` datetime DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_member_password_resets_token` (`reset_token`),
  KEY `idx_member_password_resets_email` (`email`),
  KEY `idx_member_password_resets_recipient` (`recipient_id`),
  CONSTRAINT `fk_member_password_resets_recipient`
    FOREIGN KEY (`recipient_id`) REFERENCES `recipients` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci
SQL;

    $pdo->exec($tableSql);
};