CREATE TABLE IF NOT EXISTS `wpjy_app_notification_broadcasts` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `id_contrato` BIGINT UNSIGNED NULL,
  `area` VARCHAR(20) NOT NULL DEFAULT 'adm',
  `audience` VARCHAR(40) NOT NULL DEFAULT 'admins_and_devs',
  `title` VARCHAR(160) NOT NULL,
  `message` TEXT NOT NULL,
  `link` VARCHAR(255) NULL,
  `tone` VARCHAR(20) NOT NULL DEFAULT 'info',
  `show_toast` TINYINT(1) NOT NULL DEFAULT 1,
  `show_banner` TINYINT(1) NOT NULL DEFAULT 1,
  `show_modal` TINYINT(1) NOT NULL DEFAULT 0,
  `send_push` TINYINT(1) NOT NULL DEFAULT 0,
  `include_self` TINYINT(1) NOT NULL DEFAULT 0,
  `status` VARCHAR(20) NOT NULL DEFAULT 'processing',
  `valid_until` DATETIME NULL,
  `channels_json` JSON NULL,
  `recipients_json` JSON NULL,
  `recipient_count` INT UNSIGNED NOT NULL DEFAULT 0,
  `sent_count` INT UNSIGNED NOT NULL DEFAULT 0,
  `actor_user_id` BIGINT UNSIGNED NOT NULL,
  `actor_name` VARCHAR(160) NULL,
  `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_app_notification_broadcasts_area_status` (`area`, `status`, `created_at`),
  KEY `idx_app_notification_broadcasts_contract` (`id_contrato`, `status`, `created_at`),
  KEY `idx_app_notification_broadcasts_actor` (`actor_user_id`, `created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
