CREATE TABLE facebook_pages (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    integration_id INT UNSIGNED NOT NULL,
    page_id VARCHAR(50) NOT NULL,
    name VARCHAR(150) NOT NULL,
    category VARCHAR(150) NULL,
    profile_picture_url VARCHAR(255) NULL,
    tasks TEXT NULL,
    access_token TEXT NULL,
    status ENUM('inactive','active') NOT NULL DEFAULT 'inactive',
    subscribed_at DATETIME NULL,
    unsubscribed_at DATETIME NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
    CONSTRAINT fk_facebook_page_integration FOREIGN KEY (integration_id) REFERENCES facebook_integrations (id) ON DELETE CASCADE,
    UNIQUE KEY idx_facebook_page_unique (integration_id, page_id),
    INDEX idx_facebook_page_status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
