using BomLocalService.Services.Interfaces.Registration;
using Microsoft.Playwright;
namespace BomLocalService.Services.Interfaces;
///
/// Service interface for debug file generation during web scraping operations.
/// When enabled, saves screenshots, HTML, console logs, and network request information for troubleshooting.
///
public interface IDebugService : ISingletonService
{
///
/// Indicates whether debug mode is enabled.
/// When false, debug methods return immediately without saving files.
///
bool IsEnabled { get; }
///
/// Creates a folder for storing debug files for a specific request.
/// Folder structure: {CacheDirectory}/debug/{requestId}/
///
/// Unique identifier for the request (e.g., timestamp + GUID)
/// Full path to the created debug folder, or empty string if debug is disabled
string CreateRequestFolder(string requestId);
///
/// Saves debug files for a scraping step.
/// Creates a step folder (e.g., "step_01_homepage_loaded") containing:
/// - screenshot.png (full page screenshot)
/// - page.html (complete HTML source)
/// - console.log (browser console messages)
/// - network.log (network request summary)
///
/// The debug folder path for this request (from CreateRequestFolder)
/// Step number for ordering (e.g., 1, 2, 3)
/// Descriptive name for the step (e.g., "homepage_loaded", "search_button_clicked")
/// The Playwright page instance to capture
/// Optional list of console messages to save
/// Optional list of network requests to save
/// Cancellation token to cancel the operation
Task SaveStepDebugAsync(
string requestFolder,
int stepNumber,
string stepName,
IPage page,
List<(string type, string text, DateTime timestamp)>? consoleMessages = null,
List<(string method, string url, int? status, string resourceType, DateTime timestamp)>? networkRequests = null,
CancellationToken cancellationToken = default);
///
/// Saves debug files when an error occurs during scraping.
/// Creates an "error" subfolder containing:
/// - error.txt (error message and stack trace)
/// - screenshot.png (page state at error time, if page available)
/// - page.html (HTML source at error time, if page available)
/// - console.log (console messages up to error)
/// - network.log (network requests up to error)
///
/// The debug folder path for this request (from CreateRequestFolder)
/// The error message and/or stack trace to save
/// Optional Playwright page instance to capture error state
/// Optional list of console messages to save
/// Optional list of network requests to save
/// Cancellation token to cancel the operation
Task SaveErrorDebugAsync(
string requestFolder,
string errorMessage,
IPage? page = null,
List<(string type, string text, DateTime timestamp)>? consoleMessages = null,
List<(string method, string url, int? status, string resourceType, DateTime timestamp)>? networkRequests = null,
CancellationToken cancellationToken = default);
}