-- BackPRO StatLink.pl integration - link lifecycle tracking
CREATE TABLE IF NOT EXISTS statlink_links (
    id INT AUTO_INCREMENT PRIMARY KEY,
    article_id INT NOT NULL,
    site_id INT NOT NULL,
    statlink_id INT NULL COMMENT 'ID linku w systemie StatLink.pl',
    anchor VARCHAR(500) NOT NULL,
    link_url VARCHAR(500) NOT NULL,
    added_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    expires_at DATETIME NOT NULL,
    removed_at DATETIME NULL,
    status ENUM('active', 'expired', 'removed', 'failed') NOT NULL DEFAULT 'active',
    error_message TEXT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_article_id (article_id),
    INDEX idx_status_expires (status, expires_at),
    INDEX idx_site_id (site_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
