-- Historico de disparo para alertas financeiros automaticos

CREATE TABLE IF NOT EXISTS `wpjy_fin_notification_dispatches` (
    `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    `entity_type` VARCHAR(30) NOT NULL COLLATE 'utf8mb4_0900_ai_ci',
    `entity_id` BIGINT UNSIGNED NOT NULL,
    `user_id` BIGINT UNSIGNED NOT NULL,
    `alert_type` VARCHAR(50) NOT NULL COLLATE 'utf8mb4_0900_ai_ci',
    `signature_hash` CHAR(40) NOT NULL COLLATE 'utf8mb4_0900_ai_ci',
    `payload_json` JSON NULL DEFAULT NULL,
    `notification_id` BIGINT UNSIGNED NULL DEFAULT NULL,
    `sent_at` DATETIME NOT NULL,
    `created_at` DATETIME NOT NULL,
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uk_fin_alert_signature` (`alert_type`, `signature_hash`) USING BTREE,
    INDEX `idx_fin_entity_user` (`entity_type`, `entity_id`, `user_id`) USING BTREE,
    INDEX `idx_fin_sent_at` (`sent_at`) USING BTREE
)
COLLATE='utf8mb4_0900_ai_ci'
ENGINE=InnoDB;
