<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `notification_queue` (
            `id`              BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `type`            VARCHAR(20) NOT NULL DEFAULT 'sms',
            `recipient_type`  VARCHAR(20) NOT NULL DEFAULT 'member',
            `recipient_id`    BIGINT UNSIGNED NOT NULL,
            `template_id`     BIGINT UNSIGNED NULL,
            `subject`         VARCHAR(500) NULL,
            `message`         TEXT NOT NULL,
            `data_json`       JSON NULL,
            `priority`        INT NOT NULL DEFAULT 0,
            `status`          VARCHAR(30) NOT NULL DEFAULT 'pending',
            `attempts`        INT UNSIGNED NOT NULL DEFAULT 0,
            `max_attempts`    INT UNSIGNED NOT NULL DEFAULT 3,
            `scheduled_at`    TIMESTAMP NULL DEFAULT NULL,
            `processed_at`    TIMESTAMP NULL DEFAULT NULL,
            `created_at`      TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            INDEX `idx_notif_queue_status` (`status`),
            INDEX `idx_notif_queue_type` (`type`),
            INDEX `idx_notif_queue_recipient` (`recipient_type`, `recipient_id`),
            INDEX `idx_notif_queue_scheduled` (`scheduled_at`),
            INDEX `idx_notif_queue_priority` (`priority`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `notification_queue`",
];