CREATE TABLE `wpjy_app_push_subscriptions` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `id_contrato` BIGINT UNSIGNED NULL DEFAULT NULL,
  `user_id` BIGINT UNSIGNED NOT NULL,
  `area` VARCHAR(20) NOT NULL DEFAULT 'adm' COLLATE 'utf8mb4_0900_ai_ci',
  `provider` VARCHAR(20) NOT NULL DEFAULT 'fcm' COLLATE 'utf8mb4_0900_ai_ci',
  `platform` VARCHAR(20) NOT NULL DEFAULT 'web' COLLATE 'utf8mb4_0900_ai_ci',
  `token` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_0900_ai_ci',
  `endpoint` VARCHAR(500) NULL DEFAULT NULL COLLATE 'utf8mb4_0900_ai_ci',
  `browser` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_0900_ai_ci',
  `device_label` VARCHAR(120) NULL DEFAULT NULL COLLATE 'utf8mb4_0900_ai_ci',
  `user_agent` VARCHAR(500) NULL DEFAULT NULL COLLATE 'utf8mb4_0900_ai_ci',
  `subscription_data` JSON NULL DEFAULT NULL,
  `is_active` TINYINT(1) NOT NULL DEFAULT '1',
  `last_seen_at` DATETIME NULL DEFAULT NULL,
  `last_sent_at` DATETIME NULL DEFAULT NULL,
  `last_error_at` DATETIME NULL DEFAULT NULL,
  `last_error_message` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_0900_ai_ci',
  `created_at` DATETIME NOT NULL,
  `updated_at` DATETIME NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `uk_token` (`token`) USING BTREE,
  INDEX `idx_user_area_active` (`user_id`, `area`, `is_active`) USING BTREE,
  INDEX `idx_contrato_area_active` (`id_contrato`, `area`, `is_active`) USING BTREE,
  INDEX `idx_provider_platform_active` (`provider`, `platform`, `is_active`) USING BTREE
)
COLLATE='utf8mb4_0900_ai_ci'
ENGINE=InnoDB
;
